Index: trunk/phase3/maintenance/tests/TitlePermissionTest.php |
— | — | @@ -0,0 +1,622 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class TitlePermissionTest extends PhpUnit_Framework_TestCase { |
| 5 | + static $title; |
| 6 | + static $user; |
| 7 | + static $anonUser; |
| 8 | + static $userUser; |
| 9 | + static $altUser; |
| 10 | + static $userName; |
| 11 | + static $altUserName; |
| 12 | + |
| 13 | + function setUp() { |
| 14 | + global $wgAutoloadLocalClasses; |
| 15 | + self::$userName = "Useruser"; |
| 16 | + self::$altUserName = "Altuseruser"; |
| 17 | + |
| 18 | + self::$title = Title::makeTitle(NS_MAIN, "Main Page"); |
| 19 | + self::$userUser = User::newFromName(self::$userName); |
| 20 | + if ( !self::$userUser->getID() ) { |
| 21 | + self::$userUser = User::createNew(self::$userName, array( |
| 22 | + "email" => "test@example.com", |
| 23 | + "real_name" => "Test User")); |
| 24 | + } |
| 25 | + |
| 26 | + self::$altUser = User::newFromName(self::$altUserName); |
| 27 | + if ( !self::$altUser->getID() ) { |
| 28 | + self::$altUser = User::createNew(self::$altUserName, array( |
| 29 | + "email" => "alttest@example.com", |
| 30 | + "real_name" => "Test User Alt")); |
| 31 | + } |
| 32 | + |
| 33 | + self::$anonUser = User::newFromId(0); |
| 34 | + |
| 35 | + self::$user = self::$userUser; |
| 36 | + |
| 37 | + } |
| 38 | + |
| 39 | + function setUserPerm( $perm ) { |
| 40 | + global $wgUseRCPatrol, $wgUseNPPatrol; |
| 41 | + if( is_array( $perm ) ) { |
| 42 | + self::$user->mRights = $perm; |
| 43 | + } else { |
| 44 | + self::$user->mRights = array($perm); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + function setTitle( $ns, $title = "Main_Page" ) { |
| 49 | + self::$title = Title::makeTitle($ns, $title); |
| 50 | + } |
| 51 | + |
| 52 | + function setUser( $userName = null ) { |
| 53 | + if ( $userName === 'anon' ) { |
| 54 | + self::$user = self::$anonUser; |
| 55 | + } else if ( $userName === null || $userName === self::$userName ) { |
| 56 | + self::$user = self::$userUser; |
| 57 | + } else { |
| 58 | + self::$user = self::$altUser; |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + function testQuickPermissions() { |
| 63 | + $this->setUser( 'anon' ); |
| 64 | + $this->setTitle( NS_TALK ); |
| 65 | + $this->setUserPerm( "createtalk" ); |
| 66 | + $res = self::$title->getUserPermissionsErrors( 'create', self::$user ); |
| 67 | + $this->assertEquals( array(), $res); |
| 68 | + |
| 69 | + $this->setTitle( NS_TALK ); |
| 70 | + $this->setUserPerm( "createpage" ); |
| 71 | + $res = self::$title->getUserPermissionsErrors( 'create', self::$user ); |
| 72 | + $this->assertEquals( array( array( "nocreatetext") ), $res); |
| 73 | + |
| 74 | + $this->setTitle( NS_TALK ); |
| 75 | + $this->setUserPerm( "" ); |
| 76 | + $res = self::$title->getUserPermissionsErrors( 'create', self::$user ); |
| 77 | + $this->assertEquals( array( array( 'nocreatetext' ) ), $res); |
| 78 | + |
| 79 | + $this->setTitle( NS_MAIN ); |
| 80 | + $this->setUserPerm( "createpage" ); |
| 81 | + $res = self::$title->getUserPermissionsErrors( 'create', self::$user ); |
| 82 | + $this->assertEquals( array( ), $res); |
| 83 | + |
| 84 | + $this->setTitle( NS_MAIN ); |
| 85 | + $this->setUserPerm( "createtalk" ); |
| 86 | + $res = self::$title->getUserPermissionsErrors( 'create', self::$user ); |
| 87 | + $this->assertEquals( array( array( 'nocreatetext' ) ), $res); |
| 88 | + |
| 89 | + $this->setUser( self::$userName ); |
| 90 | + $this->setTitle( NS_TALK ); |
| 91 | + $this->setUserPerm( "createtalk" ); |
| 92 | + $res = self::$title->getUserPermissionsErrors( 'create', self::$user ); |
| 93 | + $this->assertEquals( array( ), $res); |
| 94 | + |
| 95 | + $this->setTitle( NS_TALK ); |
| 96 | + $this->setUserPerm( "createpage" ); |
| 97 | + $res = self::$title->getUserPermissionsErrors( 'create', self::$user ); |
| 98 | + $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res); |
| 99 | + |
| 100 | + $this->setTitle( NS_TALK ); |
| 101 | + $this->setUserPerm( "" ); |
| 102 | + $res = self::$title->getUserPermissionsErrors( 'create', self::$user ); |
| 103 | + $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res); |
| 104 | + |
| 105 | + $this->setTitle( NS_MAIN ); |
| 106 | + $this->setUserPerm( "createpage" ); |
| 107 | + $res = self::$title->getUserPermissionsErrors( 'create', self::$user ); |
| 108 | + $this->assertEquals( array( ), $res); |
| 109 | + |
| 110 | + $this->setTitle( NS_MAIN ); |
| 111 | + $this->setUserPerm( "createtalk" ); |
| 112 | + $res = self::$title->getUserPermissionsErrors( 'create', self::$user ); |
| 113 | + $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res); |
| 114 | + |
| 115 | + $this->setTitle( NS_MAIN ); |
| 116 | + $this->setUserPerm( "" ); |
| 117 | + $res = self::$title->getUserPermissionsErrors( 'create', self::$user ); |
| 118 | + $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res); |
| 119 | + |
| 120 | + $this->setUser( 'anon' ); |
| 121 | + $this->setTitle( NS_USER, self::$userName . '' ); |
| 122 | + $this->setUserPerm( "" ); |
| 123 | + $res = self::$title->getUserPermissionsErrors( 'move', self::$user ); |
| 124 | + $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res); |
| 125 | + |
| 126 | + $this->setTitle( NS_USER, self::$userName . '/subpage' ); |
| 127 | + $this->setUserPerm( "" ); |
| 128 | + $res = self::$title->getUserPermissionsErrors( 'move', self::$user ); |
| 129 | + $this->assertEquals( array( array( 'movenologintext' ) ), $res); |
| 130 | + |
| 131 | + $this->setTitle( NS_USER, self::$userName . '' ); |
| 132 | + $this->setUserPerm( "move-rootuserpages" ); |
| 133 | + $res = self::$title->getUserPermissionsErrors( 'move', self::$user ); |
| 134 | + $this->assertEquals( array( array( 'movenologintext' ) ), $res); |
| 135 | + |
| 136 | + $this->setTitle( NS_USER, self::$userName . '/subpage' ); |
| 137 | + $this->setUserPerm( "move-rootuserpages" ); |
| 138 | + $res = self::$title->getUserPermissionsErrors( 'move', self::$user ); |
| 139 | + $this->assertEquals(array( array( 'movenologintext' ) ), $res); |
| 140 | + |
| 141 | + $this->setTitle( NS_USER, self::$userName . '' ); |
| 142 | + $this->setUserPerm( "" ); |
| 143 | + $res = self::$title->getUserPermissionsErrors( 'move', self::$user ); |
| 144 | + $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res); |
| 145 | + |
| 146 | + $this->setTitle( NS_USER, self::$userName . '/subpage' ); |
| 147 | + $this->setUserPerm( "" ); |
| 148 | + $res = self::$title->getUserPermissionsErrors( 'move', self::$user ); |
| 149 | + $this->assertEquals( array( array( 'movenologintext' ) ), $res); |
| 150 | + |
| 151 | + $this->setTitle( NS_USER, self::$userName . '' ); |
| 152 | + $this->setUserPerm( "move-rootuserpages" ); |
| 153 | + $res = self::$title->getUserPermissionsErrors( 'move', self::$user ); |
| 154 | + $this->assertEquals( array( array( 'movenologintext' ) ), $res); |
| 155 | + |
| 156 | + $this->setTitle( NS_USER, self::$userName . '/subpage' ); |
| 157 | + $this->setUserPerm( "move-rootuserpages" ); |
| 158 | + $res = self::$title->getUserPermissionsErrors( 'move', self::$user ); |
| 159 | + $this->assertEquals(array( array( 'movenologintext' ) ), $res); |
| 160 | + |
| 161 | + $this->setUser( self::$userName ); |
| 162 | + $this->setTitle( NS_FILE, "img.png" ); |
| 163 | + $this->setUserPerm( "" ); |
| 164 | + $res = self::$title->getUserPermissionsErrors( 'move', self::$user ); |
| 165 | + $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), $res); |
| 166 | + |
| 167 | + $this->setTitle( NS_FILE, "img.png" ); |
| 168 | + $this->setUserPerm( "movefile" ); |
| 169 | + $res = self::$title->getUserPermissionsErrors( 'move', self::$user ); |
| 170 | + $this->assertEquals( array( array( 'movenotallowed' ) ), $res); |
| 171 | + |
| 172 | + $this->setUser( 'anon' ); |
| 173 | + $this->setTitle( NS_FILE, "img.png" ); |
| 174 | + $this->setUserPerm( "" ); |
| 175 | + $res = self::$title->getUserPermissionsErrors( 'move', self::$user ); |
| 176 | + $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ), $res); |
| 177 | + |
| 178 | + $this->setTitle( NS_FILE, "img.png" ); |
| 179 | + $this->setUserPerm( "movefile" ); |
| 180 | + $res = self::$title->getUserPermissionsErrors( 'move', self::$user ); |
| 181 | + $this->assertEquals( array( array( 'movenologintext' ) ), $res); |
| 182 | + |
| 183 | + $this->setUser( self::$userName ); |
| 184 | + $this->setUserPerm( "move" ); |
| 185 | + $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) ); |
| 186 | + |
| 187 | + $this->setUserPerm( "" ); |
| 188 | + $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ) ); |
| 189 | + |
| 190 | + $this->setUser( 'anon' ); |
| 191 | + $this->setUserPerm( "move" ); |
| 192 | + $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) ); |
| 193 | + |
| 194 | + $this->setUserPerm( "" ); |
| 195 | + $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), |
| 196 | + array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ) ); |
| 197 | + |
| 198 | + $this->setTitle( NS_MAIN ); |
| 199 | + $this->setUser( 'anon' ); |
| 200 | + $this->setUserPerm( "move" ); |
| 201 | + $this->runGroupPermissions( 'move', array( ) ); |
| 202 | + |
| 203 | + $this->setUserPerm( "" ); |
| 204 | + $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ), |
| 205 | + array( array( 'movenologintext' ) ) ); |
| 206 | + |
| 207 | + $this->setUser( self::$userName ); |
| 208 | + $this->setUserPerm( "" ); |
| 209 | + $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) ); |
| 210 | + |
| 211 | + $this->setUserPerm( "move" ); |
| 212 | + $this->runGroupPermissions( 'move', array( ) ); |
| 213 | + |
| 214 | + $this->setUser( 'anon' ); |
| 215 | + $this->setUserPerm( 'move' ); |
| 216 | + $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user ); |
| 217 | + $this->assertEquals( array( ), $res ); |
| 218 | + |
| 219 | + $this->setUserPerm( '' ); |
| 220 | + $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user ); |
| 221 | + $this->assertEquals( array( array( 'movenotallowed' ) ), $res ); |
| 222 | + |
| 223 | + $this->setTitle( NS_USER ); |
| 224 | + $this->setUser( self::$userName ); |
| 225 | + $this->setUserPerm( array( "move", "move-rootuserpages" ) ); |
| 226 | + $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user ); |
| 227 | + $this->assertEquals( array( ), $res ); |
| 228 | + |
| 229 | + $this->setUserPerm( "move" ); |
| 230 | + $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user ); |
| 231 | + $this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res ); |
| 232 | + |
| 233 | + $this->setUser( 'anon' ); |
| 234 | + $this->setUserPerm( array( "move", "move-rootuserpages" ) ); |
| 235 | + $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user ); |
| 236 | + $this->assertEquals( array( ), $res ); |
| 237 | + |
| 238 | + $this->setTitle( NS_USER, "User/subpage" ); |
| 239 | + $this->setUserPerm( array( "move", "move-rootuserpages" ) ); |
| 240 | + $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user ); |
| 241 | + $this->assertEquals( array( ), $res ); |
| 242 | + |
| 243 | + $this->setUserPerm( "move" ); |
| 244 | + $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user ); |
| 245 | + $this->assertEquals( array( ), $res ); |
| 246 | + |
| 247 | + $this->setUser( 'anon' ); |
| 248 | + $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[Mw:Users|Users]]", 2 ) ), |
| 249 | + array( array( 'badaccess-group0' ) ), |
| 250 | + array( ), true ), |
| 251 | + 'protect' => array( array( array( 'badaccess-groups', "[[Mw:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ), |
| 252 | + array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ), |
| 253 | + array( array( 'protect-cantedit' ) ), false ), |
| 254 | + '' => array( array( ), array( ), array( ), true ) ); |
| 255 | + global $wgUser; |
| 256 | + $wgUser = self::$user; |
| 257 | + foreach(array("edit", "protect", "") as $action) { |
| 258 | + $this->setUserPerm( null ); |
| 259 | + $this->assertEquals( $check[$action][0], |
| 260 | + self::$title->getUserPermissionsErrors( $action, self::$user, true ) ); |
| 261 | + |
| 262 | + global $wgGroupPermissions; |
| 263 | + $old = $wgGroupPermissions; |
| 264 | + $wgGroupPermissions = array(); |
| 265 | + |
| 266 | + $this->assertEquals( $check[$action][1], |
| 267 | + self::$title->getUserPermissionsErrors( $action, self::$user, true ) ); |
| 268 | + $wgGroupPermissions = $old; |
| 269 | + |
| 270 | + $this->setUserPerm( $action ); |
| 271 | + $this->assertEquals( $check[$action][2], |
| 272 | + self::$title->getUserPermissionsErrors( $action, self::$user, true ) ); |
| 273 | + |
| 274 | + $this->setUserPerm( $action ); |
| 275 | + $this->assertEquals( $check[$action][3], |
| 276 | + self::$title->userCan( $action, true ) ); |
| 277 | + $this->assertEquals( $check[$action][3], |
| 278 | + self::$title->quickUserCan( $action, false ) ); |
| 279 | + |
| 280 | + # count( User::getGroupsWithPermissions( $action ) ) < 1 |
| 281 | + } |
| 282 | + } |
| 283 | + |
| 284 | + function runGroupPermissions( $action, $result, $result2 = null ) { |
| 285 | + global $wgGroupPermissions; |
| 286 | + |
| 287 | + if( $result2 === null ) $result2 = $result; |
| 288 | + |
| 289 | + $wgGroupPermissions['autoconfirmed']['move'] = false; |
| 290 | + $wgGroupPermissions['user']['move'] = false; |
| 291 | + $res = self::$title->getUserPermissionsErrors( $action, self::$user ); |
| 292 | + $this->assertEquals( $result, $res ); |
| 293 | + |
| 294 | + $wgGroupPermissions['autoconfirmed']['move'] = true; |
| 295 | + $wgGroupPermissions['user']['move'] = false; |
| 296 | + $res = self::$title->getUserPermissionsErrors( $action, self::$user ); |
| 297 | + $this->assertEquals( $result2, $res ); |
| 298 | + |
| 299 | + $wgGroupPermissions['autoconfirmed']['move'] = true; |
| 300 | + $wgGroupPermissions['user']['move'] = true; |
| 301 | + $res = self::$title->getUserPermissionsErrors( $action, self::$user ); |
| 302 | + $this->assertEquals( $result2, $res ); |
| 303 | + |
| 304 | + $wgGroupPermissions['autoconfirmed']['move'] = false; |
| 305 | + $wgGroupPermissions['user']['move'] = true; |
| 306 | + $res = self::$title->getUserPermissionsErrors( $action, self::$user ); |
| 307 | + $this->assertEquals( $result2, $res ); |
| 308 | + } |
| 309 | + |
| 310 | + function testPermissionHooks() {} |
| 311 | + function testSpecialsAndNSPermissions() { |
| 312 | + $this->setUser( self::$userName ); |
| 313 | + global $wgUser; |
| 314 | + $wgUser = self::$user; |
| 315 | + |
| 316 | + $this->setTitle( NS_SPECIAL ); |
| 317 | + |
| 318 | + $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ), |
| 319 | + self::$title->getUserPermissionsErrors( 'bogus', self::$user ) ); |
| 320 | + $this->assertEquals( array( ), |
| 321 | + self::$title->getUserPermissionsErrors( 'createaccount', self::$user ) ); |
| 322 | + $this->assertEquals( array( array( 'badaccess-group0' ) ), |
| 323 | + self::$title->getUserPermissionsErrors( 'execute', self::$user ) ); |
| 324 | + |
| 325 | + $this->setTitle( NS_MAIN ); |
| 326 | + $this->setUserPerm( 'bogus' ); |
| 327 | + $this->assertEquals( array( ), |
| 328 | + self::$title->getUserPermissionsErrors( 'bogus', self::$user ) ); |
| 329 | + |
| 330 | + $this->setTitle( NS_MAIN ); |
| 331 | + $this->setUserPerm( '' ); |
| 332 | + $this->assertEquals( array( array( 'badaccess-group0' ) ), |
| 333 | + self::$title->getUserPermissionsErrors( 'bogus', self::$user ) ); |
| 334 | + |
| 335 | + global $wgNamespaceProtection; |
| 336 | + $wgNamespaceProtection[NS_USER] = array ( 'bogus' ); |
| 337 | + $this->setTitle( NS_USER ); |
| 338 | + $this->setUserPerm( '' ); |
| 339 | + $this->assertEquals( array( array( 'badaccess-group0'), array( 'namespaceprotected', 'User' ) ), |
| 340 | + self::$title->getUserPermissionsErrors( 'bogus', self::$user ) ); |
| 341 | + |
| 342 | + $this->setTitle( NS_MEDIAWIKI ); |
| 343 | + $this->setUserPerm( 'bogus' ); |
| 344 | + $this->assertEquals( array( array( 'protectedinterface' ) ), |
| 345 | + self::$title->getUserPermissionsErrors( 'bogus', self::$user ) ); |
| 346 | + |
| 347 | + $this->setTitle( NS_MEDIAWIKI ); |
| 348 | + $this->setUserPerm( 'bogus' ); |
| 349 | + $this->assertEquals( array( array( 'protectedinterface' ) ), |
| 350 | + self::$title->getUserPermissionsErrors( 'bogus', self::$user ) ); |
| 351 | + |
| 352 | + $wgNamespaceProtection = null; |
| 353 | + $this->setUserPerm( 'bogus' ); |
| 354 | + $this->assertEquals( array( ), |
| 355 | + self::$title->getUserPermissionsErrors( 'bogus', self::$user ) ); |
| 356 | + $this->assertEquals( true, |
| 357 | + self::$title->userCan( 'bogus' ) ); |
| 358 | + |
| 359 | + $this->setUserPerm( '' ); |
| 360 | + $this->assertEquals( array( array( 'badaccess-group0' ) ), |
| 361 | + self::$title->getUserPermissionsErrors( 'bogus', self::$user ) ); |
| 362 | + $this->assertEquals( false, |
| 363 | + self::$title->userCan( 'bogus' ) ); |
| 364 | + } |
| 365 | + |
| 366 | + function testCSSandJSPermissions() { |
| 367 | + $this->setUser( self::$userName ); |
| 368 | + global $wgUser; |
| 369 | + $wgUser = self::$user; |
| 370 | + |
| 371 | + $this->setTitle( NS_USER, self::$altUserName .'/test.js' ); |
| 372 | + $this->runCSSandJSPermissions( |
| 373 | + array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ), |
| 374 | + array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ), |
| 375 | + array( array( 'badaccess-group0' ) ) ); |
| 376 | + |
| 377 | + $this->setTitle( NS_USER, self::$altUserName .'/test.css' ); |
| 378 | + $this->runCSSandJSPermissions( |
| 379 | + array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ), |
| 380 | + array( array( 'badaccess-group0' ) ), |
| 381 | + array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ) ); |
| 382 | + |
| 383 | + $this->setTitle( NS_USER, self::$altUserName .'/tempo' ); |
| 384 | + $this->runCSSandJSPermissions( |
| 385 | + array( array( 'badaccess-group0' ) ), |
| 386 | + array( array( 'badaccess-group0' ) ), |
| 387 | + array( array( 'badaccess-group0' ) ) ); |
| 388 | + } |
| 389 | + |
| 390 | + function runCSSandJSPermissions( $result0, $result1, $result2 ) { |
| 391 | + $this->setUserPerm( '' ); |
| 392 | + $this->assertEquals( $result0, |
| 393 | + self::$title->getUserPermissionsErrors( 'bogus', |
| 394 | + self::$user ) ); |
| 395 | + |
| 396 | + $this->setUserPerm( 'editusercss' ); |
| 397 | + $this->assertEquals( $result1, |
| 398 | + self::$title->getUserPermissionsErrors( 'bogus', |
| 399 | + self::$user ) ); |
| 400 | + |
| 401 | + $this->setUserPerm( 'edituserjs' ); |
| 402 | + $this->assertEquals( $result2, |
| 403 | + self::$title->getUserPermissionsErrors( 'bogus', |
| 404 | + self::$user ) ); |
| 405 | + |
| 406 | + $this->setUserPerm( 'editusercssjs' ); |
| 407 | + $this->assertEquals( array( array( 'badaccess-group0' ) ), |
| 408 | + self::$title->getUserPermissionsErrors( 'bogus', |
| 409 | + self::$user ) ); |
| 410 | + |
| 411 | + $this->setUserPerm( array( 'edituserjs', 'editusercss' ) ); |
| 412 | + $this->assertEquals( array( array( 'badaccess-group0' ) ), |
| 413 | + self::$title->getUserPermissionsErrors( 'bogus', |
| 414 | + self::$user ) ); |
| 415 | + } |
| 416 | + |
| 417 | + function testPageRestrictions() { |
| 418 | + global $wgUser; |
| 419 | + $wgUser = self::$user; |
| 420 | + $this->setTitle( NS_MAIN ); |
| 421 | + self::$title->mRestrictionsLoaded = true; |
| 422 | + $this->setUserPerm("edit"); |
| 423 | + self::$title->mRestrictions= array("bogus" => array('bogus', "sysop", "protect", "")); |
| 424 | + |
| 425 | + $this->assertEquals( array( ), |
| 426 | + self::$title->getUserPermissionsErrors( 'edit', |
| 427 | + self::$user ) ); |
| 428 | + |
| 429 | + $this->assertEquals( true, |
| 430 | + self::$title->quickUserCan( 'edit', false ) ); |
| 431 | + self::$title->mRestrictions= array("edit" => array('bogus', "sysop", "protect", ""), |
| 432 | + "bogus" => array('bogus', "sysop", "protect", "")); |
| 433 | + |
| 434 | + $this->assertEquals( array( array( 'badaccess-group0' ), |
| 435 | + array( 'protectedpagetext', 'bogus' ), |
| 436 | + array( 'protectedpagetext', 'protect' ), |
| 437 | + array( 'protectedpagetext', 'protect' ) ), |
| 438 | + self::$title->getUserPermissionsErrors( 'bogus', |
| 439 | + self::$user ) ); |
| 440 | + $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ), |
| 441 | + array( 'protectedpagetext', 'protect' ), |
| 442 | + array( 'protectedpagetext', 'protect' ) ), |
| 443 | + self::$title->getUserPermissionsErrors( 'edit', |
| 444 | + self::$user ) ); |
| 445 | + $this->setUserPerm(""); |
| 446 | + $this->assertEquals( array( array( 'badaccess-group0' ), |
| 447 | + array( 'protectedpagetext', 'bogus' ), |
| 448 | + array( 'protectedpagetext', 'protect' ), |
| 449 | + array( 'protectedpagetext', 'protect' ) ), |
| 450 | + self::$title->getUserPermissionsErrors( 'bogus', |
| 451 | + self::$user ) ); |
| 452 | + $this->assertEquals( array( array( 'badaccess-groups', '*, [[Mw:Users|Users]]', 2 ), |
| 453 | + array( 'protectedpagetext', 'bogus' ), |
| 454 | + array( 'protectedpagetext', 'protect' ), |
| 455 | + array( 'protectedpagetext', 'protect' ) ), |
| 456 | + self::$title->getUserPermissionsErrors( 'edit', |
| 457 | + self::$user ) ); |
| 458 | + $this->setUserPerm(array("edit", "editprotected") ); |
| 459 | + $this->assertEquals( array( array( 'badaccess-group0' ), |
| 460 | + array( 'protectedpagetext', 'bogus' ), |
| 461 | + array( 'protectedpagetext', 'protect' ), |
| 462 | + array( 'protectedpagetext', 'protect' ) ), |
| 463 | + self::$title->getUserPermissionsErrors( 'bogus', |
| 464 | + self::$user ) ); |
| 465 | + $this->assertEquals( array( ), |
| 466 | + self::$title->getUserPermissionsErrors( 'edit', |
| 467 | + self::$user ) ); |
| 468 | + self::$title->mCascadeRestriction = true; |
| 469 | + $this->assertEquals( false, |
| 470 | + self::$title->quickUserCan( 'bogus', false ) ); |
| 471 | + $this->assertEquals( false, |
| 472 | + self::$title->quickUserCan( 'edit', false ) ); |
| 473 | + $this->assertEquals( array( array( 'badaccess-group0' ), |
| 474 | + array( 'protectedpagetext', 'bogus' ), |
| 475 | + array( 'protectedpagetext', 'protect' ), |
| 476 | + array( 'protectedpagetext', 'protect' ) ), |
| 477 | + self::$title->getUserPermissionsErrors( 'bogus', |
| 478 | + self::$user ) ); |
| 479 | + $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ), |
| 480 | + array( 'protectedpagetext', 'protect' ), |
| 481 | + array( 'protectedpagetext', 'protect' ) ), |
| 482 | + self::$title->getUserPermissionsErrors( 'edit', |
| 483 | + self::$user ) ); |
| 484 | + } |
| 485 | + |
| 486 | + function testCascadingSourcesRestrictions() { |
| 487 | + global $wgUser; |
| 488 | + $wgUser = self::$user; |
| 489 | + $this->setTitle(NS_MAIN, "test page"); |
| 490 | + $this->setUserPerm(array("edit", "bogus")); |
| 491 | + |
| 492 | + self::$title->mCascadeSources = array( Title::makeTitle(NS_MAIN, "Bogus"), Title::makeTitle(NS_MAIN, "UnBogus") ); |
| 493 | + self::$title->mCascadingRestrictions = array( "bogus" => array('bogus', "sysop", "protect", "" ) ); |
| 494 | + |
| 495 | + $this->assertEquals( false, |
| 496 | + self::$title->userCan( 'bogus' ) ); |
| 497 | + $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ), |
| 498 | + array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ), |
| 499 | + self::$title->getUserPermissionsErrors( 'bogus', self::$user ) ); |
| 500 | + |
| 501 | + $this->assertEquals( true, |
| 502 | + self::$title->userCan( 'edit' ) ); |
| 503 | + $this->assertEquals( array( ), |
| 504 | + self::$title->getUserPermissionsErrors( 'edit', self::$user ) ); |
| 505 | + |
| 506 | + } |
| 507 | + |
| 508 | + function testActionPermissions() { |
| 509 | + global $wgUser; |
| 510 | + $wgUser = self::$user; |
| 511 | + |
| 512 | + $this->setUserPerm( array( "createpage" ) ); |
| 513 | + $this->setTitle(NS_MAIN, "test page"); |
| 514 | + self::$title->mTitleProtection['pt_create_perm'] = ''; |
| 515 | + self::$title->mTitleProtection['pt_user'] = 1; |
| 516 | + self::$title->mTitleProtection['pt_expiry'] = Block::infinity(); |
| 517 | + self::$title->mTitleProtection['pt_reason'] = 'test'; |
| 518 | + self::$title->mCascadeRestriction = false; |
| 519 | + |
| 520 | + $this->assertEquals( array( array( 'titleprotected', 'WikiSysop', 'test' ) ), |
| 521 | + self::$title->getUserPermissionsErrors( 'create', self::$user ) ); |
| 522 | + $this->assertEquals( false, |
| 523 | + self::$title->userCan( 'create' ) ); |
| 524 | + |
| 525 | + self::$title->mTitleProtection['pt_create_perm'] = 'sysop'; |
| 526 | + $this->setUserPerm( array( 'createpage', 'protect' ) ); |
| 527 | + $this->assertEquals( array( ), |
| 528 | + self::$title->getUserPermissionsErrors( 'create', self::$user ) ); |
| 529 | + $this->assertEquals( true, |
| 530 | + self::$title->userCan( 'create' ) ); |
| 531 | + |
| 532 | + |
| 533 | + $this->setUserPerm( array( 'createpage' ) ); |
| 534 | + $this->assertEquals( array( array( 'titleprotected', 'WikiSysop', 'test' ) ), |
| 535 | + self::$title->getUserPermissionsErrors( 'create', self::$user ) ); |
| 536 | + $this->assertEquals( false, |
| 537 | + self::$title->userCan( 'create' ) ); |
| 538 | + |
| 539 | + $this->setTitle( NS_MEDIA, "test page" ); |
| 540 | + $this->setUserPerm( array( "move" ) ); |
| 541 | + $this->assertEquals( false, |
| 542 | + self::$title->userCan( 'move' ) ); |
| 543 | + $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ), |
| 544 | + self::$title->getUserPermissionsErrors( 'move', self::$user ) ); |
| 545 | + |
| 546 | + $this->setTitle( NS_MAIN, "test page" ); |
| 547 | + $this->assertEquals( array( ), |
| 548 | + self::$title->getUserPermissionsErrors( 'move', self::$user ) ); |
| 549 | + $this->assertEquals( true, |
| 550 | + self::$title->userCan( 'move' ) ); |
| 551 | + |
| 552 | + self::$title->mInterwiki = "no"; |
| 553 | + $this->assertEquals( array( array( 'immobile-page' ) ), |
| 554 | + self::$title->getUserPermissionsErrors( 'move', self::$user ) ); |
| 555 | + $this->assertEquals( false, |
| 556 | + self::$title->userCan( 'move' ) ); |
| 557 | + |
| 558 | + $this->setTitle( NS_MEDIA, "test page" ); |
| 559 | + $this->assertEquals( false, |
| 560 | + self::$title->userCan( 'move-target' ) ); |
| 561 | + $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ), |
| 562 | + self::$title->getUserPermissionsErrors( 'move-target', self::$user ) ); |
| 563 | + |
| 564 | + $this->setTitle( NS_MAIN, "test page" ); |
| 565 | + $this->assertEquals( array( ), |
| 566 | + self::$title->getUserPermissionsErrors( 'move-target', self::$user ) ); |
| 567 | + $this->assertEquals( true, |
| 568 | + self::$title->userCan( 'move-target' ) ); |
| 569 | + |
| 570 | + self::$title->mInterwiki = "no"; |
| 571 | + $this->assertEquals( array( array( 'immobile-target-page' ) ), |
| 572 | + self::$title->getUserPermissionsErrors( 'move-target', self::$user ) ); |
| 573 | + $this->assertEquals( false, |
| 574 | + self::$title->userCan( 'move-target' ) ); |
| 575 | + |
| 576 | + } |
| 577 | + |
| 578 | + function testUserBlock() { |
| 579 | + global $wgUser, $wgEmailConfirmToEdit, $wgEmailAuthentication; |
| 580 | + $wgEmailConfirmToEdit = true; |
| 581 | + $wgEmailAuthentication = true; |
| 582 | + $wgUser = self::$user; |
| 583 | + |
| 584 | + $this->setUserPerm( array( "createpage", "move" ) ); |
| 585 | + $this->setTitle(NS_MAIN, "test page"); |
| 586 | + |
| 587 | + # $short |
| 588 | + $this->assertEquals( array( array( 'confirmedittext' ) ), |
| 589 | + self::$title->getUserPermissionsErrors( 'move-target', self::$user ) ); |
| 590 | + $this->assertEquals( true, self::$title->userCan( 'move-target' ) ); |
| 591 | + |
| 592 | + $wgEmailConfirmToEdit = false; |
| 593 | + # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount' |
| 594 | + $this->assertEquals( array( ), |
| 595 | + self::$title->getUserPermissionsErrors( 'move-target', |
| 596 | + self::$user ) ); |
| 597 | + |
| 598 | + self::$user->mBlockedby = 1; |
| 599 | + self::$user->mBlock = new Block('127.0.8.1', 2, 1, 'no reason given', '888', 10); |
| 600 | + $this->assertEquals( array( array( 'autoblockedtext', |
| 601 | + '[[User:WikiSysop|WikiSysop]]', 'no reason given', '127.0.0.1', |
| 602 | + 'WikiSysop', 0, 'infinite', '127.0.8.1', '00:14, 1 January 1970' ) ), |
| 603 | + self::$title->getUserPermissionsErrors( 'move-target', |
| 604 | + self::$user ) ); |
| 605 | + |
| 606 | + $this->assertEquals( true, |
| 607 | + self::$title->userCan( 'move-target', self::$user ) ); |
| 608 | + |
| 609 | + global $wgLang; |
| 610 | + $now = time() + 120; |
| 611 | + self::$user->mBlockedby = 'WikiSysop'; |
| 612 | + self::$user->mBlock = new Block('127.0.8.1', 2, 1, 'no reason given', $now, 0, 10 ); |
| 613 | + $this->assertEquals( array( array( 'blockedtext', |
| 614 | + '[[User:WikiSysop|WikiSysop]]', 'no reason given', '127.0.0.1', |
| 615 | + 'WikiSysop', 0, '00:00, 1 January 1970', '127.0.8.1', |
| 616 | + $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ) ), |
| 617 | + self::$title->getUserPermissionsErrors( 'move-target', self::$user ) ); |
| 618 | + |
| 619 | + # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this ) |
| 620 | + # $user->blockedFor() == '' |
| 621 | + # $user->mBlock->mExpiry == 'infinity' |
| 622 | + } |
| 623 | +} |
\ No newline at end of file |
Property changes on: trunk/phase3/maintenance/tests/TitlePermissionTest.php |
___________________________________________________________________ |
Name: svn:eol-syle |
1 | 624 | + native |
Index: trunk/phase3/includes/Title.php |
— | — | @@ -10,7 +10,7 @@ |
11 | 11 | * and is loaded by UtfNormalUtil.php, which is loaded by UtfNormal.php. |
12 | 12 | */ |
13 | 13 | if ( !class_exists( 'UtfNormal' ) ) { |
14 | | - require_once( dirname(__FILE__) . '/normal/UtfNormal.php' ); |
| 14 | + require_once( dirname( __FILE__ ) . '/normal/UtfNormal.php' ); |
15 | 15 | } |
16 | 16 | |
17 | 17 | define ( 'GAID_FOR_UPDATE', 1 ); |
— | — | @@ -25,10 +25,10 @@ |
26 | 26 | */ |
27 | 27 | class Title { |
28 | 28 | /** @name Static cache variables */ |
29 | | - //@{ |
30 | | - static private $titleCache=array(); |
31 | | - static private $interwikiCache=array(); |
32 | | - //@} |
| 29 | + // @{ |
| 30 | + static private $titleCache = array(); |
| 31 | + static private $interwikiCache = array(); |
| 32 | + // @} |
33 | 33 | |
34 | 34 | /** |
35 | 35 | * Title::newFromText maintains a cache to avoid expensive re-normalization of |
— | — | @@ -43,18 +43,18 @@ |
44 | 44 | * Please use the accessor functions instead. |
45 | 45 | * @private |
46 | 46 | */ |
47 | | - //@{ |
| 47 | + // @{ |
48 | 48 | |
49 | | - var $mTextform = ''; ///< Text form (spaces not underscores) of the main part |
50 | | - var $mUrlform = ''; ///< URL-encoded form of the main part |
51 | | - var $mDbkeyform = ''; ///< Main part with underscores |
52 | | - var $mUserCaseDBKey; ///< DB key with the initial letter in the case specified by the user |
53 | | - var $mNamespace = NS_MAIN; ///< Namespace index, i.e. one of the NS_xxxx constants |
54 | | - var $mInterwiki = ''; ///< Interwiki prefix (or null string) |
55 | | - var $mFragment; ///< Title fragment (i.e. the bit after the #) |
56 | | - var $mArticleID = -1; ///< Article ID, fetched from the link cache on demand |
57 | | - var $mLatestID = false; ///< ID of most recent revision |
58 | | - var $mRestrictions = array(); ///< Array of groups allowed to edit this article |
| 49 | + var $mTextform = ''; // /< Text form (spaces not underscores) of the main part |
| 50 | + var $mUrlform = ''; // /< URL-encoded form of the main part |
| 51 | + var $mDbkeyform = ''; // /< Main part with underscores |
| 52 | + var $mUserCaseDBKey; // /< DB key with the initial letter in the case specified by the user |
| 53 | + var $mNamespace = NS_MAIN; // /< Namespace index, i.e. one of the NS_xxxx constants |
| 54 | + var $mInterwiki = ''; // /< Interwiki prefix (or null string) |
| 55 | + var $mFragment; // /< Title fragment (i.e. the bit after the #) |
| 56 | + var $mArticleID = -1; // /< Article ID, fetched from the link cache on demand |
| 57 | + var $mLatestID = false; // /< ID of most recent revision |
| 58 | + var $mRestrictions = array(); // /< Array of groups allowed to edit this article |
59 | 59 | var $mOldRestrictions = false; |
60 | 60 | var $mCascadeRestriction; ///< Cascade restrictions on this page to included templates and images? |
61 | 61 | var $mCascadingRestrictions; // Caching the results of getCascadeProtectionSources |
— | — | @@ -66,21 +66,21 @@ |
67 | 67 | var $mTitleProtection; ///< Cached value of getTitleProtection |
68 | 68 | # Don't change the following default, NS_MAIN is hardcoded in several |
69 | 69 | # places. See bug 696. |
70 | | - var $mDefaultNamespace = NS_MAIN; ///< Namespace index when there is no namespace |
| 70 | + var $mDefaultNamespace = NS_MAIN; // /< Namespace index when there is no namespace |
71 | 71 | # Zero except in {{transclusion}} tags |
72 | | - var $mWatched = null; ///< Is $wgUser watching this page? null if unfilled, accessed through userIsWatching() |
73 | | - var $mLength = -1; ///< The page length, 0 for special pages |
74 | | - var $mRedirect = null; ///< Is the article at this title a redirect? |
75 | | - var $mNotificationTimestamp = array(); ///< Associative array of user ID -> timestamp/false |
76 | | - var $mBacklinkCache = null; ///< Cache of links to this title |
77 | | - //@} |
| 72 | + var $mWatched = null; // /< Is $wgUser watching this page? null if unfilled, accessed through userIsWatching() |
| 73 | + var $mLength = -1; // /< The page length, 0 for special pages |
| 74 | + var $mRedirect = null; // /< Is the article at this title a redirect? |
| 75 | + var $mNotificationTimestamp = array(); // /< Associative array of user ID -> timestamp/false |
| 76 | + var $mBacklinkCache = null; // /< Cache of links to this title |
| 77 | + // @} |
78 | 78 | |
79 | 79 | |
80 | 80 | /** |
81 | 81 | * Constructor |
82 | 82 | * @private |
83 | 83 | */ |
84 | | - /* private */ function __construct() {} |
| 84 | + /* private */ function __construct() { } |
85 | 85 | |
86 | 86 | /** |
87 | 87 | * Create a new Title from a prefixed DB key |
— | — | @@ -93,7 +93,7 @@ |
94 | 94 | public static function newFromDBkey( $key ) { |
95 | 95 | $t = new Title(); |
96 | 96 | $t->mDbkeyform = $key; |
97 | | - if( $t->secureAndSplit() ) |
| 97 | + if ( $t->secureAndSplit() ) |
98 | 98 | return $t; |
99 | 99 | else |
100 | 100 | return null; |
— | — | @@ -112,7 +112,7 @@ |
113 | 113 | * @return Title The new object, or null on an error. |
114 | 114 | */ |
115 | 115 | public static function newFromText( $text, $defaultNamespace = NS_MAIN ) { |
116 | | - if( is_object( $text ) ) { |
| 116 | + if ( is_object( $text ) ) { |
117 | 117 | throw new MWException( 'Title::newFromText given an object' ); |
118 | 118 | } |
119 | 119 | |
— | — | @@ -124,7 +124,7 @@ |
125 | 125 | * |
126 | 126 | * In theory these are value objects and won't get changed... |
127 | 127 | */ |
128 | | - if( $defaultNamespace == NS_MAIN && isset( Title::$titleCache[$text] ) ) { |
| 128 | + if ( $defaultNamespace == NS_MAIN && isset( Title::$titleCache[$text] ) ) { |
129 | 129 | return Title::$titleCache[$text]; |
130 | 130 | } |
131 | 131 | |
— | — | @@ -138,12 +138,12 @@ |
139 | 139 | $t->mDefaultNamespace = $defaultNamespace; |
140 | 140 | |
141 | 141 | static $cachedcount = 0 ; |
142 | | - if( $t->secureAndSplit() ) { |
143 | | - if( $defaultNamespace == NS_MAIN ) { |
144 | | - if( $cachedcount >= self::CACHE_MAX ) { |
| 142 | + if ( $t->secureAndSplit() ) { |
| 143 | + if ( $defaultNamespace == NS_MAIN ) { |
| 144 | + if ( $cachedcount >= self::CACHE_MAX ) { |
145 | 145 | # Avoid memory leaks on mass operations... |
146 | 146 | Title::$titleCache = array(); |
147 | | - $cachedcount=0; |
| 147 | + $cachedcount = 0; |
148 | 148 | } |
149 | 149 | $cachedcount++; |
150 | 150 | Title::$titleCache[$text] =& $t; |
— | — | @@ -182,7 +182,7 @@ |
183 | 183 | } |
184 | 184 | |
185 | 185 | $t->mDbkeyform = str_replace( ' ', '_', $url ); |
186 | | - if( $t->secureAndSplit() ) { |
| 186 | + if ( $t->secureAndSplit() ) { |
187 | 187 | return $t; |
188 | 188 | } else { |
189 | 189 | return null; |
— | — | @@ -197,9 +197,9 @@ |
198 | 198 | * @return \type{Title} the new object, or NULL on an error |
199 | 199 | */ |
200 | 200 | public static function newFromID( $id, $flags = 0 ) { |
201 | | - $db = ($flags & GAID_FOR_UPDATE) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); |
| 201 | + $db = ( $flags & GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); |
202 | 202 | $row = $db->selectRow( 'page', '*', array( 'page_id' => $id ), __METHOD__ ); |
203 | | - if( $row !== false ) { |
| 203 | + if ( $row !== false ) { |
204 | 204 | $title = Title::newFromRow( $row ); |
205 | 205 | } else { |
206 | 206 | $title = null; |
— | — | @@ -222,7 +222,7 @@ |
223 | 223 | 'page_id IN (' . $dbr->makeList( $ids ) . ')', __METHOD__ ); |
224 | 224 | |
225 | 225 | $titles = array(); |
226 | | - foreach( $res as $row ) { |
| 226 | + foreach ( $res as $row ) { |
227 | 227 | $titles[] = Title::makeTitle( $row->page_namespace, $row->page_title ); |
228 | 228 | } |
229 | 229 | return $titles; |
— | — | @@ -237,10 +237,10 @@ |
238 | 238 | public static function newFromRow( $row ) { |
239 | 239 | $t = self::makeTitle( $row->page_namespace, $row->page_title ); |
240 | 240 | |
241 | | - $t->mArticleID = isset($row->page_id) ? intval($row->page_id) : -1; |
242 | | - $t->mLength = isset($row->page_len) ? intval($row->page_len) : -1; |
243 | | - $t->mRedirect = isset($row->page_is_redirect) ? (bool)$row->page_is_redirect : null; |
244 | | - $t->mLatestID = isset($row->page_latest) ? $row->page_latest : false; |
| 241 | + $t->mArticleID = isset( $row->page_id ) ? intval( $row->page_id ) : -1; |
| 242 | + $t->mLength = isset( $row->page_len ) ? intval( $row->page_len ) : -1; |
| 243 | + $t->mRedirect = isset( $row->page_is_redirect ) ? (bool)$row->page_is_redirect : null; |
| 244 | + $t->mLatestID = isset( $row->page_latest ) ? $row->page_latest : false; |
245 | 245 | |
246 | 246 | return $t; |
247 | 247 | } |
— | — | @@ -282,7 +282,7 @@ |
283 | 283 | public static function makeTitleSafe( $ns, $title, $fragment = '' ) { |
284 | 284 | $t = new Title(); |
285 | 285 | $t->mDbkeyform = Title::makeName( $ns, $title, $fragment ); |
286 | | - if( $t->secureAndSplit() ) { |
| 286 | + if ( $t->secureAndSplit() ) { |
287 | 287 | return $t; |
288 | 288 | } else { |
289 | 289 | return null; |
— | — | @@ -342,23 +342,23 @@ |
343 | 343 | public static function newFromRedirectArray( $text ) { |
344 | 344 | global $wgMaxRedirects; |
345 | 345 | // are redirects disabled? |
346 | | - if( $wgMaxRedirects < 1 ) |
| 346 | + if ( $wgMaxRedirects < 1 ) |
347 | 347 | return null; |
348 | 348 | $title = self::newFromRedirectInternal( $text ); |
349 | | - if( is_null( $title ) ) |
| 349 | + if ( is_null( $title ) ) |
350 | 350 | return null; |
351 | 351 | // recursive check to follow double redirects |
352 | 352 | $recurse = $wgMaxRedirects; |
353 | 353 | $titles = array( $title ); |
354 | | - while( --$recurse > 0 ) { |
355 | | - if( $title->isRedirect() ) { |
| 354 | + while ( --$recurse > 0 ) { |
| 355 | + if ( $title->isRedirect() ) { |
356 | 356 | $article = new Article( $title, 0 ); |
357 | 357 | $newtitle = $article->getRedirectTarget(); |
358 | 358 | } else { |
359 | 359 | break; |
360 | 360 | } |
361 | 361 | // Redirects to some special pages are not permitted |
362 | | - if( $newtitle instanceOf Title && $newtitle->isValidRedirectTarget() ) { |
| 362 | + if ( $newtitle instanceOf Title && $newtitle->isValidRedirectTarget() ) { |
363 | 363 | // the new title passes the checks, so make that our current title so that further recursion can be checked |
364 | 364 | $title = $newtitle; |
365 | 365 | $titles[] = $newtitle; |
— | — | @@ -378,16 +378,16 @@ |
379 | 379 | */ |
380 | 380 | protected static function newFromRedirectInternal( $text ) { |
381 | 381 | $redir = MagicWord::get( 'redirect' ); |
382 | | - $text = trim($text); |
383 | | - if( $redir->matchStartAndRemove( $text ) ) { |
| 382 | + $text = trim( $text ); |
| 383 | + if ( $redir->matchStartAndRemove( $text ) ) { |
384 | 384 | // Extract the first link and see if it's usable |
385 | 385 | // Ensure that it really does come directly after #REDIRECT |
386 | 386 | // Some older redirects included a colon, so don't freak about that! |
387 | 387 | $m = array(); |
388 | | - if( preg_match( '!^\s*:?\s*\[{2}(.*?)(?:\|.*?)?\]{2}!', $text, $m ) ) { |
| 388 | + if ( preg_match( '!^\s*:?\s*\[{2}(.*?)(?:\|.*?)?\]{2}!', $text, $m ) ) { |
389 | 389 | // Strip preceding colon used to "escape" categories, etc. |
390 | 390 | // and URL-decode links |
391 | | - if( strpos( $m[1], '%' ) !== false ) { |
| 391 | + if ( strpos( $m[1], '%' ) !== false ) { |
392 | 392 | // Match behavior of inline link parsing here; |
393 | 393 | // don't interpret + as " " most of the time! |
394 | 394 | // It might be safe to just use rawurldecode instead, though. |
— | — | @@ -395,7 +395,7 @@ |
396 | 396 | } |
397 | 397 | $title = Title::newFromText( $m[1] ); |
398 | 398 | // If the title is a redirect to bad special pages or is invalid, return null |
399 | | - if( !$title instanceof Title || !$title->isValidRedirectTarget() ) { |
| 399 | + if ( !$title instanceof Title || !$title->isValidRedirectTarget() ) { |
400 | 400 | return null; |
401 | 401 | } |
402 | 402 | return $title; |
— | — | @@ -404,9 +404,9 @@ |
405 | 405 | return null; |
406 | 406 | } |
407 | 407 | |
408 | | -#---------------------------------------------------------------------------- |
| 408 | +# ---------------------------------------------------------------------------- |
409 | 409 | # Static functions |
410 | | -#---------------------------------------------------------------------------- |
| 410 | +# ---------------------------------------------------------------------------- |
411 | 411 | |
412 | 412 | /** |
413 | 413 | * Get the prefixed DB key associated with an ID |
— | — | @@ -419,7 +419,7 @@ |
420 | 420 | $dbr = wfGetDB( DB_SLAVE ); |
421 | 421 | |
422 | 422 | $s = $dbr->selectRow( 'page', |
423 | | - array( 'page_namespace','page_title' ), |
| 423 | + array( 'page_namespace', 'page_title' ), |
424 | 424 | array( 'page_id' => $id ), |
425 | 425 | __METHOD__ ); |
426 | 426 | if ( $s === false ) { return null; } |
— | — | @@ -508,7 +508,7 @@ |
509 | 509 | * @return \type{\bool} TRUE if this is transcludable |
510 | 510 | */ |
511 | 511 | public function isTrans() { |
512 | | - if ($this->mInterwiki == '') |
| 512 | + if ( $this->mInterwiki == '' ) |
513 | 513 | return false; |
514 | 514 | |
515 | 515 | return Interwiki::fetch( $this->mInterwiki )->isTranscludable(); |
— | — | @@ -516,7 +516,7 @@ |
517 | 517 | |
518 | 518 | /** |
519 | 519 | * Escape a text fragment, say from a link, for a URL |
520 | | - * |
| 520 | + * |
521 | 521 | * @param $fragment string containing a URL or link fragment (after the "#") |
522 | 522 | * @return String: escaped string |
523 | 523 | */ |
— | — | @@ -528,9 +528,9 @@ |
529 | 529 | return Sanitizer::escapeId( $fragment, 'noninitial' ); |
530 | 530 | } |
531 | 531 | |
532 | | -#---------------------------------------------------------------------------- |
| 532 | +# ---------------------------------------------------------------------------- |
533 | 533 | # Other stuff |
534 | | -#---------------------------------------------------------------------------- |
| 534 | +# ---------------------------------------------------------------------------- |
535 | 535 | |
536 | 536 | /** Simple accessors */ |
537 | 537 | /** |
— | — | @@ -576,7 +576,7 @@ |
577 | 577 | // |
578 | 578 | // Use the canonical namespaces if possible to try to |
579 | 579 | // resolve a foreign namespace. |
580 | | - if( MWNamespace::exists( $this->mNamespace ) ) { |
| 580 | + if ( MWNamespace::exists( $this->mNamespace ) ) { |
581 | 581 | return MWNamespace::getCanonicalName( $this->mNamespace ); |
582 | 582 | } |
583 | 583 | } |
— | — | @@ -700,7 +700,7 @@ |
701 | 701 | */ |
702 | 702 | public function getFullText() { |
703 | 703 | $text = $this->getPrefixedText(); |
704 | | - if( $this->mFragment != '' ) { |
| 704 | + if ( $this->mFragment != '' ) { |
705 | 705 | $text .= '#' . $this->mFragment; |
706 | 706 | } |
707 | 707 | return $text; |
— | — | @@ -712,13 +712,13 @@ |
713 | 713 | * @return \type{\string} Base name |
714 | 714 | */ |
715 | 715 | public function getBaseText() { |
716 | | - if( !MWNamespace::hasSubpages( $this->mNamespace ) ) { |
| 716 | + if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) { |
717 | 717 | return $this->getText(); |
718 | 718 | } |
719 | 719 | |
720 | 720 | $parts = explode( '/', $this->getText() ); |
721 | 721 | # Don't discard the real title if there's no subpage involved |
722 | | - if( count( $parts ) > 1 ) |
| 722 | + if ( count( $parts ) > 1 ) |
723 | 723 | unset( $parts[ count( $parts ) - 1 ] ); |
724 | 724 | return implode( '/', $parts ); |
725 | 725 | } |
— | — | @@ -729,7 +729,7 @@ |
730 | 730 | * @return \type{\string} Subpage name |
731 | 731 | */ |
732 | 732 | public function getSubpageText() { |
733 | | - if( !MWNamespace::hasSubpages( $this->mNamespace ) ) { |
| 733 | + if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) { |
734 | 734 | return( $this->mTextform ); |
735 | 735 | } |
736 | 736 | $parts = explode( '/', $this->mTextform ); |
— | — | @@ -771,7 +771,7 @@ |
772 | 772 | public function getFullURL( $query = '', $variant = false ) { |
773 | 773 | global $wgContLang, $wgServer, $wgRequest; |
774 | 774 | |
775 | | - if( is_array( $query ) ) { |
| 775 | + if ( is_array( $query ) ) { |
776 | 776 | $query = wfArrayToCGI( $query ); |
777 | 777 | } |
778 | 778 | |
— | — | @@ -781,7 +781,7 @@ |
782 | 782 | |
783 | 783 | // Ugly quick hack to avoid duplicate prefixes (bug 4571 etc) |
784 | 784 | // Correct fix would be to move the prepending elsewhere. |
785 | | - if ($wgRequest->getVal('action') != 'render') { |
| 785 | + if ( $wgRequest->getVal( 'action' ) != 'render' ) { |
786 | 786 | $url = $wgServer . $url; |
787 | 787 | } |
788 | 788 | } else { |
— | — | @@ -819,14 +819,14 @@ |
820 | 820 | global $wgArticlePath, $wgScript, $wgServer, $wgRequest; |
821 | 821 | global $wgVariantArticlePath, $wgContLang, $wgUser; |
822 | 822 | |
823 | | - if( is_array( $query ) ) { |
| 823 | + if ( is_array( $query ) ) { |
824 | 824 | $query = wfArrayToCGI( $query ); |
825 | 825 | } |
826 | 826 | |
827 | 827 | // internal links should point to same variant as current page (only anonymous users) |
828 | | - if($variant == false && $wgContLang->hasVariants() && !$wgUser->isLoggedIn()){ |
829 | | - $pref = $wgContLang->getPreferredVariant(false); |
830 | | - if($pref != $wgContLang->getCode()) |
| 828 | + if ( $variant == false && $wgContLang->hasVariants() && !$wgUser->isLoggedIn() ) { |
| 829 | + $pref = $wgContLang->getPreferredVariant( false ); |
| 830 | + if ( $pref != $wgContLang->getCode() ) |
831 | 831 | $variant = $pref; |
832 | 832 | } |
833 | 833 | |
— | — | @@ -842,8 +842,8 @@ |
843 | 843 | } else { |
844 | 844 | $dbkey = wfUrlencode( $this->getPrefixedDBkey() ); |
845 | 845 | if ( $query == '' ) { |
846 | | - if( $variant != false && $wgContLang->hasVariants() ) { |
847 | | - if( $wgVariantArticlePath == false ) { |
| 846 | + if ( $variant != false && $wgContLang->hasVariants() ) { |
| 847 | + if ( $wgVariantArticlePath == false ) { |
848 | 848 | $variantArticlePath = "$wgScript?title=$1&variant=$2"; // default |
849 | 849 | } else { |
850 | 850 | $variantArticlePath = $wgVariantArticlePath; |
— | — | @@ -857,15 +857,15 @@ |
858 | 858 | global $wgActionPaths; |
859 | 859 | $url = false; |
860 | 860 | $matches = array(); |
861 | | - if( !empty( $wgActionPaths ) && |
| 861 | + if ( !empty( $wgActionPaths ) && |
862 | 862 | preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches ) ) |
863 | 863 | { |
864 | 864 | $action = urldecode( $matches[2] ); |
865 | | - if( isset( $wgActionPaths[$action] ) ) { |
| 865 | + if ( isset( $wgActionPaths[$action] ) ) { |
866 | 866 | $query = $matches[1]; |
867 | | - if( isset( $matches[4] ) ) $query .= $matches[4]; |
| 867 | + if ( isset( $matches[4] ) ) $query .= $matches[4]; |
868 | 868 | $url = str_replace( '$1', $dbkey, $wgActionPaths[$action] ); |
869 | | - if( $query != '' ) { |
| 869 | + if ( $query != '' ) { |
870 | 870 | $url = wfAppendQuery( $url, $query ); |
871 | 871 | } |
872 | 872 | } |
— | — | @@ -880,7 +880,7 @@ |
881 | 881 | |
882 | 882 | // FIXME: this causes breakage in various places when we |
883 | 883 | // actually expected a local URL and end up with dupe prefixes. |
884 | | - if ($wgRequest->getVal('action') == 'render') { |
| 884 | + if ( $wgRequest->getVal( 'action' ) == 'render' ) { |
885 | 885 | $url = $wgServer . $url; |
886 | 886 | } |
887 | 887 | } |
— | — | @@ -907,9 +907,9 @@ |
908 | 908 | */ |
909 | 909 | public function getLinkUrl( $query = array(), $variant = false ) { |
910 | 910 | wfProfileIn( __METHOD__ ); |
911 | | - if( $this->isExternal() ) { |
| 911 | + if ( $this->isExternal() ) { |
912 | 912 | $ret = $this->getFullURL( $query ); |
913 | | - } elseif( $this->getPrefixedText() === '' && $this->getFragment() !== '' ) { |
| 913 | + } elseif ( $this->getPrefixedText() === '' && $this->getFragment() !== '' ) { |
914 | 914 | $ret = $this->getFragmentForURL(); |
915 | 915 | } else { |
916 | 916 | $ret = $this->getLocalURL( $query, $variant ) . $this->getFragmentForURL(); |
— | — | @@ -993,11 +993,11 @@ |
994 | 994 | * @return \type{\bool} |
995 | 995 | */ |
996 | 996 | public function isSemiProtected( $action = 'edit' ) { |
997 | | - if( $this->exists() ) { |
| 997 | + if ( $this->exists() ) { |
998 | 998 | $restrictions = $this->getRestrictions( $action ); |
999 | | - if( count( $restrictions ) > 0 ) { |
1000 | | - foreach( $restrictions as $restriction ) { |
1001 | | - if( strtolower( $restriction ) != 'autoconfirmed' ) |
| 999 | + if ( count( $restrictions ) > 0 ) { |
| 1000 | + foreach ( $restrictions as $restriction ) { |
| 1001 | + if ( strtolower( $restriction ) != 'autoconfirmed' ) |
1002 | 1002 | return false; |
1003 | 1003 | } |
1004 | 1004 | } else { |
— | — | @@ -1028,11 +1028,11 @@ |
1029 | 1029 | return true; |
1030 | 1030 | |
1031 | 1031 | # Check regular protection levels |
1032 | | - foreach( $restrictionTypes as $type ){ |
1033 | | - if( $action == $type || $action == '' ) { |
| 1032 | + foreach ( $restrictionTypes as $type ) { |
| 1033 | + if ( $action == $type || $action == '' ) { |
1034 | 1034 | $r = $this->getRestrictions( $type ); |
1035 | | - foreach( $wgRestrictionLevels as $level ) { |
1036 | | - if( in_array( $level, $r ) && $level != '' ) { |
| 1035 | + foreach ( $wgRestrictionLevels as $level ) { |
| 1036 | + if ( in_array( $level, $r ) && $level != '' ) { |
1037 | 1037 | return true; |
1038 | 1038 | } |
1039 | 1039 | } |
— | — | @@ -1065,7 +1065,7 @@ |
1066 | 1066 | global $wgUser; |
1067 | 1067 | |
1068 | 1068 | if ( is_null( $this->mWatched ) ) { |
1069 | | - if ( NS_SPECIAL == $this->mNamespace || !$wgUser->isLoggedIn()) { |
| 1069 | + if ( NS_SPECIAL == $this->mNamespace || !$wgUser->isLoggedIn() ) { |
1070 | 1070 | $this->mWatched = false; |
1071 | 1071 | } else { |
1072 | 1072 | $this->mWatched = $wgUser->isWatched( $this ); |
— | — | @@ -1099,9 +1099,9 @@ |
1100 | 1100 | */ |
1101 | 1101 | public function isNamespaceProtected() { |
1102 | 1102 | global $wgNamespaceProtection, $wgUser; |
1103 | | - if( isset( $wgNamespaceProtection[ $this->mNamespace ] ) ) { |
1104 | | - foreach( (array)$wgNamespaceProtection[ $this->mNamespace ] as $right ) { |
1105 | | - if( $right != '' && !$wgUser->isAllowed( $right ) ) |
| 1103 | + if ( isset( $wgNamespaceProtection[ $this->mNamespace ] ) ) { |
| 1104 | + foreach ( (array)$wgNamespaceProtection[ $this->mNamespace ] as $right ) { |
| 1105 | + if ( $right != '' && !$wgUser->isAllowed( $right ) ) |
1106 | 1106 | return true; |
1107 | 1107 | } |
1108 | 1108 | } |
— | — | @@ -1117,7 +1117,7 @@ |
1118 | 1118 | */ |
1119 | 1119 | public function userCan( $action, $doExpensiveQueries = true ) { |
1120 | 1120 | global $wgUser; |
1121 | | - return ($this->getUserPermissionsErrorsInternal( $action, $wgUser, $doExpensiveQueries, true ) === array()); |
| 1121 | + return ( $this->getUserPermissionsErrorsInternal( $action, $wgUser, $doExpensiveQueries, true ) === array() ); |
1122 | 1122 | } |
1123 | 1123 | |
1124 | 1124 | /** |
— | — | @@ -1132,79 +1132,22 @@ |
1133 | 1133 | * @return \type{\array} Array of arrays of the arguments to wfMsg to explain permissions problems. |
1134 | 1134 | */ |
1135 | 1135 | public function getUserPermissionsErrors( $action, $user, $doExpensiveQueries = true, $ignoreErrors = array() ) { |
1136 | | - if( !StubObject::isRealObject( $user ) ) { |
1137 | | - //Since StubObject is always used on globals, we can unstub $wgUser here and set $user = $wgUser |
| 1136 | + if ( !StubObject::isRealObject( $user ) ) { |
| 1137 | + // Since StubObject is always used on globals, we can |
| 1138 | + // unstub $wgUser here and set $user = $wgUser |
1138 | 1139 | global $wgUser; |
1139 | 1140 | $wgUser->_unstub( '', 5 ); |
1140 | 1141 | $user = $wgUser; |
1141 | 1142 | } |
| 1143 | + |
1142 | 1144 | $errors = $this->getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries ); |
1143 | 1145 | |
1144 | | - global $wgContLang; |
1145 | | - global $wgLang; |
1146 | | - global $wgEmailConfirmToEdit; |
1147 | | - |
1148 | | - if ( $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount' ) { |
1149 | | - $errors[] = array( 'confirmedittext' ); |
1150 | | - } |
1151 | | - |
1152 | | - // Edit blocks should not affect reading. Account creation blocks handled at userlogin. |
1153 | | - if ( $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this ) ) { |
1154 | | - $block = $user->mBlock; |
1155 | | - |
1156 | | - // This is from OutputPage::blockedPage |
1157 | | - // Copied at r23888 by werdna |
1158 | | - |
1159 | | - $id = $user->blockedBy(); |
1160 | | - $reason = $user->blockedFor(); |
1161 | | - if( $reason == '' ) { |
1162 | | - $reason = wfMsg( 'blockednoreason' ); |
1163 | | - } |
1164 | | - $ip = wfGetIP(); |
1165 | | - |
1166 | | - if ( is_numeric( $id ) ) { |
1167 | | - $name = User::whoIs( $id ); |
1168 | | - } else { |
1169 | | - $name = $id; |
1170 | | - } |
1171 | | - |
1172 | | - $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]"; |
1173 | | - $blockid = $block->mId; |
1174 | | - $blockExpiry = $user->mBlock->mExpiry; |
1175 | | - $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW, $user->mBlock->mTimestamp ), true ); |
1176 | | - |
1177 | | - if ( $blockExpiry == 'infinity' ) { |
1178 | | - // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite' |
1179 | | - $scBlockExpiryOptions = wfMsg( 'ipboptions' ); |
1180 | | - |
1181 | | - foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) { |
1182 | | - if ( strpos( $option, ':' ) == false ) |
1183 | | - continue; |
1184 | | - |
1185 | | - list ($show, $value) = explode( ":", $option ); |
1186 | | - |
1187 | | - if ( $value == 'infinite' || $value == 'indefinite' ) { |
1188 | | - $blockExpiry = $show; |
1189 | | - break; |
1190 | | - } |
1191 | | - } |
1192 | | - } else { |
1193 | | - $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW, $blockExpiry ), true ); |
1194 | | - } |
1195 | | - |
1196 | | - $intended = $user->mBlock->mAddress; |
1197 | | - |
1198 | | - $errors[] = array( ($block->mAuto ? 'autoblockedtext' : 'blockedtext'), $link, $reason, $ip, $name, |
1199 | | - $blockid, $blockExpiry, $intended, $blockTimestamp ); |
1200 | | - } |
1201 | | - |
1202 | 1146 | // Remove the errors being ignored. |
| 1147 | + foreach ( $errors as $index => $error ) { |
| 1148 | + $error_key = is_array( $error ) ? $error[0] : $error; |
1203 | 1149 | |
1204 | | - foreach( $errors as $index => $error ) { |
1205 | | - $error_key = is_array($error) ? $error[0] : $error; |
1206 | | - |
1207 | | - if (in_array( $error_key, $ignoreErrors )) { |
1208 | | - unset($errors[$index]); |
| 1150 | + if ( in_array( $error_key, $ignoreErrors ) ) { |
| 1151 | + unset( $errors[$index] ); |
1209 | 1152 | } |
1210 | 1153 | } |
1211 | 1154 | |
— | — | @@ -1212,36 +1155,35 @@ |
1213 | 1156 | } |
1214 | 1157 | |
1215 | 1158 | /** |
1216 | | - * Can $user perform $action on this page? This is an internal function, |
1217 | | - * which checks ONLY that previously checked by userCan (i.e. it leaves out |
1218 | | - * checks on wfReadOnly() and blocks) |
| 1159 | + * Permissions checks that fail most often, and which are easiest to test. |
1219 | 1160 | * |
1220 | | - * @param $action \type{\string} action that permission needs to be checked for |
1221 | | - * @param $user \type{User} user to check |
1222 | | - * @param $doExpensiveQueries \type{\bool} Set this to false to avoid doing unnecessary queries. |
1223 | | - * @param $short \type{\bool} Set this to true to stop after the first permission error. |
1224 | | - * @return \type{\array} Array of arrays of the arguments to wfMsg to explain permissions problems. |
| 1161 | + * @param $action String the action to check |
| 1162 | + * @param $user User user to check |
| 1163 | + * @param $errors Array list of current errors |
| 1164 | + * @param $doExpensiveQueries Boolean whether or not to perform expensive queries |
| 1165 | + * @param $short Boolean short circuit on first error |
| 1166 | + * |
| 1167 | + * @return Array list of errors |
1225 | 1168 | */ |
1226 | | - private function getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries=true, $short=false ) { |
1227 | | - wfProfileIn( __METHOD__ ); |
1228 | | - |
1229 | | - $errors = array(); |
1230 | | - |
1231 | | - // First stop is permissions checks, which fail most often, and which are easiest to test. |
1232 | | - if ( $action == 'move' ) { |
1233 | | - if( !$user->isAllowed( 'move-rootuserpages' ) |
1234 | | - && $this->getNamespace() == NS_USER && !$this->isSubpage() ) |
1235 | | - { |
| 1169 | + private function checkQuickPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) { |
| 1170 | + if ( $action == 'create' ) { |
| 1171 | + if ( ( $this->isTalkPage() && !$user->isAllowed( 'createtalk' ) ) || |
| 1172 | + ( !$this->isTalkPage() && !$user->isAllowed( 'createpage' ) ) ) { |
| 1173 | + $errors[] = $user->isAnon() ? array ( 'nocreatetext' ) : array ( 'nocreate-loggedin' ); |
| 1174 | + } |
| 1175 | + } elseif ( $action == 'move' ) { |
| 1176 | + if ( !$user->isAllowed( 'move-rootuserpages' ) |
| 1177 | + && $this->mNamespace == NS_USER && !$this->isSubpage() ) { |
1236 | 1178 | // Show user page-specific message only if the user can move other pages |
1237 | 1179 | $errors[] = array( 'cant-move-user-page' ); |
1238 | 1180 | } |
1239 | 1181 | |
1240 | 1182 | // Check if user is allowed to move files if it's a file |
1241 | | - if( $this->getNamespace() == NS_FILE && !$user->isAllowed( 'movefile' ) ) { |
| 1183 | + if ( $this->mNamespace == NS_FILE && !$user->isAllowed( 'movefile' ) ) { |
1242 | 1184 | $errors[] = array( 'movenotallowedfile' ); |
1243 | 1185 | } |
1244 | 1186 | |
1245 | | - if( !$user->isAllowed( 'move' ) ) { |
| 1187 | + if ( !$user->isAllowed( 'move' ) ) { |
1246 | 1188 | // User can't move anything |
1247 | 1189 | global $wgGroupPermissions; |
1248 | 1190 | $userCanMove = false; |
— | — | @@ -1256,40 +1198,33 @@ |
1257 | 1199 | // custom message if logged-in users without any special rights can move |
1258 | 1200 | $errors[] = array ( 'movenologintext' ); |
1259 | 1201 | } else { |
1260 | | - $errors[] = array ('movenotallowed'); |
| 1202 | + $errors[] = array ( 'movenotallowed' ); |
1261 | 1203 | } |
1262 | 1204 | } |
1263 | | - } elseif ( $action == 'create' ) { |
1264 | | - if( ( $this->isTalkPage() && !$user->isAllowed( 'createtalk' ) ) || |
1265 | | - ( !$this->isTalkPage() && !$user->isAllowed( 'createpage' ) ) ) |
1266 | | - { |
1267 | | - $errors[] = $user->isAnon() ? array ('nocreatetext') : array ('nocreate-loggedin'); |
1268 | | - } |
1269 | | - } elseif( $action == 'move-target' ) { |
1270 | | - if( !$user->isAllowed( 'move' ) ) { |
| 1205 | + } elseif ( $action == 'move-target' ) { |
| 1206 | + if ( !$user->isAllowed( 'move' ) ) { |
1271 | 1207 | // User can't move anything |
1272 | | - $errors[] = array ('movenotallowed'); |
1273 | | - } elseif( !$user->isAllowed( 'move-rootuserpages' ) |
1274 | | - && $this->getNamespace() == NS_USER && !$this->isSubpage() ) |
1275 | | - { |
| 1208 | + $errors[] = array ( 'movenotallowed' ); |
| 1209 | + } elseif ( !$user->isAllowed( 'move-rootuserpages' ) |
| 1210 | + && $this->mNamespace == NS_USER && !$this->isSubpage() ) { |
1276 | 1211 | // Show user page-specific message only if the user can move other pages |
1277 | 1212 | $errors[] = array( 'cant-move-to-user-page' ); |
1278 | 1213 | } |
1279 | | - } elseif( !$user->isAllowed( $action ) ) { |
| 1214 | + } elseif ( !$user->isAllowed( $action ) ) { |
1280 | 1215 | $return = null; |
1281 | 1216 | |
1282 | 1217 | // We avoid expensive display logic for quickUserCan's and such |
1283 | 1218 | $groups = false; |
1284 | | - if (!$short) { |
| 1219 | + if ( !$short ) { |
1285 | 1220 | $groups = array_map( array( 'User', 'makeGroupLinkWiki' ), |
1286 | 1221 | User::getGroupsWithPermission( $action ) ); |
1287 | 1222 | } |
1288 | 1223 | |
1289 | | - if( $groups ) { |
| 1224 | + if ( $groups ) { |
1290 | 1225 | global $wgLang; |
1291 | | - $return = array( |
| 1226 | + $return = array( |
1292 | 1227 | 'badaccess-groups', |
1293 | | - $wgLang->commaList( $groups ), |
| 1228 | + $wgLang->commaList( $groups ), |
1294 | 1229 | count( $groups ) |
1295 | 1230 | ); |
1296 | 1231 | } else { |
— | — | @@ -1298,95 +1233,119 @@ |
1299 | 1234 | $errors[] = $return; |
1300 | 1235 | } |
1301 | 1236 | |
1302 | | - # Short-circuit point |
1303 | | - if( $short && count($errors) > 0 ) { |
1304 | | - wfProfileOut( __METHOD__ ); |
1305 | | - return $errors; |
| 1237 | + return $errors; |
| 1238 | + } |
| 1239 | + |
| 1240 | + /** |
| 1241 | + * Add the resulting error code to the errors array |
| 1242 | + * |
| 1243 | + * @param $errors Array list of current errors |
| 1244 | + * @param $result Mixed result of errors |
| 1245 | + * |
| 1246 | + * @return Array list of errors |
| 1247 | + */ |
| 1248 | + private function resultToError( $errors, $result ) { |
| 1249 | + if ( is_array( $result ) && count( $result ) && !is_array( $result[0] ) ) { |
| 1250 | + // A single array representing an error |
| 1251 | + $errors[] = $result; |
| 1252 | + } else if ( is_array( $result ) && is_array( $result[0] ) ) { |
| 1253 | + // A nested array representing multiple errors |
| 1254 | + $errors = array_merge( $errors, $result ); |
| 1255 | + } else if ( $result !== '' && is_string( $result ) ) { |
| 1256 | + // A string representing a message-id |
| 1257 | + $errors[] = array( $result ); |
| 1258 | + } else if ( $result === false ) { |
| 1259 | + // a generic "We don't want them to do that" |
| 1260 | + $errors[] = array( 'badaccess-group0' ); |
1306 | 1261 | } |
| 1262 | + return $errors; |
| 1263 | + } |
1307 | 1264 | |
| 1265 | + /** |
| 1266 | + * Check various permission hooks |
| 1267 | + * @see checkQuickPermissions for parameter information |
| 1268 | + */ |
| 1269 | + private function checkPermissionHooks( $action, $user, $errors, $doExpensiveQueries, $short ) { |
1308 | 1270 | // Use getUserPermissionsErrors instead |
1309 | | - if( !wfRunHooks( 'userCan', array( &$this, &$user, $action, &$result ) ) ) { |
1310 | | - wfProfileOut( __METHOD__ ); |
| 1271 | + if ( !wfRunHooks( 'userCan', array( &$this, &$user, $action, &$result ) ) ) { |
1311 | 1272 | return $result ? array() : array( array( 'badaccess-group0' ) ); |
1312 | 1273 | } |
1313 | 1274 | // Check getUserPermissionsErrors hook |
1314 | | - if( !wfRunHooks( 'getUserPermissionsErrors', array(&$this,&$user,$action,&$result) ) ) { |
1315 | | - if( is_array($result) && count($result) && !is_array($result[0]) ) |
1316 | | - $errors[] = $result; # A single array representing an error |
1317 | | - else if( is_array($result) && is_array($result[0]) ) |
1318 | | - $errors = array_merge( $errors, $result ); # A nested array representing multiple errors |
1319 | | - else if( $result !== '' && is_string($result) ) |
1320 | | - $errors[] = array($result); # A string representing a message-id |
1321 | | - else if( $result === false ) |
1322 | | - $errors[] = array('badaccess-group0'); # a generic "We don't want them to do that" |
| 1275 | + if ( !wfRunHooks( 'getUserPermissionsErrors', array( &$this, &$user, $action, &$result ) ) ) { |
| 1276 | + $errors[] = $this->resultToError( $errors, $result ); |
1323 | 1277 | } |
1324 | | - # Short-circuit point |
1325 | | - if( $short && count($errors) > 0 ) { |
1326 | | - wfProfileOut( __METHOD__ ); |
1327 | | - return $errors; |
1328 | | - } |
1329 | 1278 | // Check getUserPermissionsErrorsExpensive hook |
1330 | | - if( $doExpensiveQueries && !wfRunHooks( 'getUserPermissionsErrorsExpensive', array(&$this,&$user,$action,&$result) ) ) { |
1331 | | - if( is_array($result) && count($result) && !is_array($result[0]) ) |
1332 | | - $errors[] = $result; # A single array representing an error |
1333 | | - else if( is_array($result) && is_array($result[0]) ) |
1334 | | - $errors = array_merge( $errors, $result ); # A nested array representing multiple errors |
1335 | | - else if( $result !== '' && is_string($result) ) |
1336 | | - $errors[] = array($result); # A string representing a message-id |
1337 | | - else if( $result === false ) |
1338 | | - $errors[] = array('badaccess-group0'); # a generic "We don't want them to do that" |
| 1279 | + if ( $doExpensiveQueries && !( $short && count( $errors ) > 0 ) && |
| 1280 | + !wfRunHooks( 'getUserPermissionsErrorsExpensive', array( &$this, &$user, $action, &$result ) ) ) { |
| 1281 | + $errors[] = $this->resultToError( $errors, $result ); |
1339 | 1282 | } |
1340 | | - # Short-circuit point |
1341 | | - if( $short && count($errors) > 0 ) { |
1342 | | - wfProfileOut( __METHOD__ ); |
1343 | | - return $errors; |
1344 | | - } |
1345 | 1283 | |
| 1284 | + return $errors; |
| 1285 | + } |
| 1286 | + |
| 1287 | + /** |
| 1288 | + * Check permissions on special pages & namespaces |
| 1289 | + * @see checkQuickPermissions for parameter information |
| 1290 | + */ |
| 1291 | + private function checkSpecialsAndNSPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) { |
1346 | 1292 | # Only 'createaccount' and 'execute' can be performed on |
1347 | 1293 | # special pages, which don't actually exist in the DB. |
1348 | 1294 | $specialOKActions = array( 'createaccount', 'execute' ); |
1349 | | - if( NS_SPECIAL == $this->mNamespace && !in_array( $action, $specialOKActions) ) { |
1350 | | - $errors[] = array('ns-specialprotected'); |
| 1295 | + if ( NS_SPECIAL == $this->mNamespace && !in_array( $action, $specialOKActions ) ) { |
| 1296 | + $errors[] = array( 'ns-specialprotected' ); |
1351 | 1297 | } |
1352 | 1298 | |
1353 | 1299 | # Check $wgNamespaceProtection for restricted namespaces |
1354 | | - if( $this->isNamespaceProtected() ) { |
1355 | | - $ns = $this->getNamespace() == NS_MAIN ? |
| 1300 | + if ( $this->isNamespaceProtected() ) { |
| 1301 | + $ns = $this->mNamespace == NS_MAIN ? |
1356 | 1302 | wfMsg( 'nstab-main' ) : $this->getNsText(); |
1357 | | - $errors[] = NS_MEDIAWIKI == $this->mNamespace ? |
1358 | | - array('protectedinterface') : array( 'namespaceprotected', $ns ); |
| 1303 | + $errors[] = $this->mNamespace == NS_MEDIAWIKI ? |
| 1304 | + array( 'protectedinterface' ) : array( 'namespaceprotected', $ns ); |
1359 | 1305 | } |
1360 | 1306 | |
| 1307 | + return $errors; |
| 1308 | + } |
| 1309 | + |
| 1310 | + /** |
| 1311 | + * Check CSS/JS sub-page permissions |
| 1312 | + * @see checkQuickPermissions for parameter information |
| 1313 | + */ |
| 1314 | + private function checkCSSandJSPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) { |
1361 | 1315 | # Protect css/js subpages of user pages |
1362 | 1316 | # XXX: this might be better using restrictions |
1363 | 1317 | # XXX: Find a way to work around the php bug that prevents using $this->userCanEditCssSubpage() |
1364 | 1318 | # and $this->userCanEditJsSubpage() from working |
1365 | 1319 | # XXX: right 'editusercssjs' is deprecated, for backward compatibility only |
1366 | | - if( $this->isCssSubpage() && !( $user->isAllowed('editusercssjs') || $user->isAllowed('editusercss') ) |
1367 | | - && $action != 'patrol' |
1368 | | - && !preg_match('/^'.preg_quote($user->getName(), '/').'\//', $this->mTextform) ) |
1369 | | - { |
1370 | | - $errors[] = array('customcssjsprotected'); |
1371 | | - } else if( $this->isJsSubpage() && !( $user->isAllowed('editusercssjs') || $user->isAllowed('edituserjs') ) |
1372 | | - && $action != 'patrol' |
1373 | | - && !preg_match('/^'.preg_quote($user->getName(), '/').'\//', $this->mTextform) ) |
1374 | | - { |
1375 | | - $errors[] = array('customcssjsprotected'); |
| 1320 | + if ( $action != 'patrol' && !$user->isAllowed( 'editusercssjs' ) |
| 1321 | + && !preg_match( '/^' . preg_quote( $user->getName(), '/' ) . '\//', $this->mTextform ) ) { |
| 1322 | + if ( $this->isCssSubpage() && !$user->isAllowed( 'editusercss' ) ) { |
| 1323 | + $errors[] = array( 'customcssjsprotected' ); |
| 1324 | + } else if ( $this->isJsSubpage() && !$user->isAllowed( 'edituserjs' ) ) { |
| 1325 | + $errors[] = array( 'customcssjsprotected' ); |
| 1326 | + } |
1376 | 1327 | } |
1377 | 1328 | |
1378 | | - # Check against page_restrictions table requirements on this |
1379 | | - # page. The user must possess all required rights for this action. |
1380 | | - foreach( $this->getRestrictions($action) as $right ) { |
| 1329 | + return $errors; |
| 1330 | + } |
| 1331 | + |
| 1332 | + /** |
| 1333 | + * Check against page_restrictions table requirements on this |
| 1334 | + * page. The user must possess all required rights for this |
| 1335 | + * action. |
| 1336 | + * @see checkQuickPermissions for parameter information |
| 1337 | + */ |
| 1338 | + private function checkPageRestrictions( $action, $user, $errors, $doExpensiveQueries, $short ) { |
| 1339 | + foreach ( $this->getRestrictions( $action ) as $right ) { |
1381 | 1340 | // Backwards compatibility, rewrite sysop -> protect |
1382 | | - if( $right == 'sysop' ) { |
| 1341 | + if ( $right == 'sysop' ) { |
1383 | 1342 | $right = 'protect'; |
1384 | 1343 | } |
1385 | | - if( $right != '' && !$user->isAllowed( $right ) ) { |
| 1344 | + if ( $right != '' && !$user->isAllowed( $right ) ) { |
1386 | 1345 | // Users with 'editprotected' permission can edit protected pages |
1387 | | - if( $action=='edit' && $user->isAllowed( 'editprotected' ) ) { |
| 1346 | + if ( $action == 'edit' && $user->isAllowed( 'editprotected' ) ) { |
1388 | 1347 | // Users with 'editprotected' permission cannot edit protected pages |
1389 | 1348 | // with cascading option turned on. |
1390 | | - if( $this->mCascadeRestriction ) { |
| 1349 | + if ( $this->mCascadeRestriction ) { |
1391 | 1350 | $errors[] = array( 'protectedpagetext', $right ); |
1392 | 1351 | } |
1393 | 1352 | } else { |
— | — | @@ -1394,73 +1353,180 @@ |
1395 | 1354 | } |
1396 | 1355 | } |
1397 | 1356 | } |
1398 | | - # Short-circuit point |
1399 | | - if( $short && count($errors) > 0 ) { |
1400 | | - wfProfileOut( __METHOD__ ); |
1401 | | - return $errors; |
1402 | | - } |
1403 | 1357 | |
1404 | | - if( $doExpensiveQueries && !$this->isCssJsSubpage() ) { |
1405 | | - # We /could/ use the protection level on the source page, but it's fairly ugly |
1406 | | - # as we have to establish a precedence hierarchy for pages included by multiple |
1407 | | - # cascade-protected pages. So just restrict it to people with 'protect' permission, |
1408 | | - # as they could remove the protection anyway. |
| 1358 | + return $errors; |
| 1359 | + } |
| 1360 | + |
| 1361 | + /** |
| 1362 | + * Check restrictions on cascading pages. |
| 1363 | + * @see checkQuickPermissions for parameter information |
| 1364 | + */ |
| 1365 | + private function checkCascadingSourcesRestrictions( $action, $user, $errors, $doExpensiveQueries, $short ) { |
| 1366 | + if ( $doExpensiveQueries && !$this->isCssJsSubpage() ) { |
| 1367 | + # We /could/ use the protection level on the source page, but it's |
| 1368 | + # fairly ugly as we have to establish a precedence hierarchy for pages |
| 1369 | + # included by multiple cascade-protected pages. So just restrict |
| 1370 | + # it to people with 'protect' permission, as they could remove the |
| 1371 | + # protection anyway. |
1409 | 1372 | list( $cascadingSources, $restrictions ) = $this->getCascadeProtectionSources(); |
1410 | 1373 | # Cascading protection depends on more than this page... |
1411 | 1374 | # Several cascading protected pages may include this page... |
1412 | 1375 | # Check each cascading level |
1413 | 1376 | # This is only for protection restrictions, not for all actions |
1414 | | - if( isset($restrictions[$action]) ) { |
1415 | | - foreach( $restrictions[$action] as $right ) { |
| 1377 | + if ( isset( $restrictions[$action] ) ) { |
| 1378 | + foreach ( $restrictions[$action] as $right ) { |
1416 | 1379 | $right = ( $right == 'sysop' ) ? 'protect' : $right; |
1417 | | - if( $right != '' && !$user->isAllowed( $right ) ) { |
| 1380 | + if ( $right != '' && !$user->isAllowed( $right ) ) { |
1418 | 1381 | $pages = ''; |
1419 | | - foreach( $cascadingSources as $page ) |
| 1382 | + foreach ( $cascadingSources as $page ) |
1420 | 1383 | $pages .= '* [[:' . $page->getPrefixedText() . "]]\n"; |
1421 | 1384 | $errors[] = array( 'cascadeprotected', count( $cascadingSources ), $pages ); |
1422 | 1385 | } |
1423 | 1386 | } |
1424 | 1387 | } |
1425 | 1388 | } |
1426 | | - # Short-circuit point |
1427 | | - if( $short && count($errors) > 0 ) { |
1428 | | - wfProfileOut( __METHOD__ ); |
1429 | | - return $errors; |
1430 | | - } |
1431 | 1389 | |
1432 | | - if( $action == 'protect' ) { |
1433 | | - if( $this->getUserPermissionsErrors('edit', $user) != array() ) { |
1434 | | - $errors[] = array( 'protect-cantedit' ); // If they can't edit, they shouldn't protect. |
| 1390 | + return $errors; |
| 1391 | + } |
| 1392 | + |
| 1393 | + /** |
| 1394 | + * Check action permissions not already checked in checkQuickPermissions |
| 1395 | + * @see checkQuickPermissions for parameter information |
| 1396 | + */ |
| 1397 | + private function checkActionPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) { |
| 1398 | + if ( $action == 'protect' ) { |
| 1399 | + if ( $this->getUserPermissionsErrors( 'edit', $user ) != array() ) { |
| 1400 | + // If they can't edit, they shouldn't protect. |
| 1401 | + $errors[] = array( 'protect-cantedit' ); |
1435 | 1402 | } |
1436 | | - } |
1437 | | - |
1438 | | - if( $action == 'create' ) { |
| 1403 | + } elseif ( $action == 'create' ) { |
1439 | 1404 | $title_protection = $this->getTitleProtection(); |
1440 | 1405 | if( $title_protection ) { |
1441 | 1406 | if( $title_protection['pt_create_perm'] == 'sysop' ) { |
1442 | 1407 | $title_protection['pt_create_perm'] = 'protect'; // B/C |
1443 | 1408 | } |
1444 | | - if( $title_protection['pt_create_perm'] == '' || !$user->isAllowed($title_protection['pt_create_perm']) ) { |
1445 | | - $errors[] = array( 'titleprotected', User::whoIs($title_protection['pt_user']), $title_protection['pt_reason'] ); |
| 1409 | + if( $title_protection['pt_create_perm'] == '' || !$user->isAllowed( $title_protection['pt_create_perm'] ) ) { |
| 1410 | + $errors[] = array( 'titleprotected', User::whoIs( $title_protection['pt_user'] ), $title_protection['pt_reason'] ); |
1446 | 1411 | } |
1447 | 1412 | } |
1448 | | - } elseif( $action == 'move' ) { |
| 1413 | + } elseif ( $action == 'move' ) { |
1449 | 1414 | // Check for immobile pages |
1450 | | - if( !MWNamespace::isMovable( $this->getNamespace() ) ) { |
| 1415 | + if ( !MWNamespace::isMovable( $this->mNamespace ) ) { |
1451 | 1416 | // Specific message for this case |
1452 | 1417 | $errors[] = array( 'immobile-source-namespace', $this->getNsText() ); |
1453 | | - } elseif( !$this->isMovable() ) { |
| 1418 | + } elseif ( !$this->isMovable() ) { |
1454 | 1419 | // Less specific message for rarer cases |
1455 | 1420 | $errors[] = array( 'immobile-page' ); |
1456 | 1421 | } |
1457 | | - } elseif( $action == 'move-target' ) { |
1458 | | - if( !MWNamespace::isMovable( $this->getNamespace() ) ) { |
| 1422 | + } elseif ( $action == 'move-target' ) { |
| 1423 | + if ( !MWNamespace::isMovable( $this->mNamespace ) ) { |
1459 | 1424 | $errors[] = array( 'immobile-target-namespace', $this->getNsText() ); |
1460 | | - } elseif( !$this->isMovable() ) { |
| 1425 | + } elseif ( !$this->isMovable() ) { |
1461 | 1426 | $errors[] = array( 'immobile-target-page' ); |
1462 | 1427 | } |
1463 | 1428 | } |
| 1429 | + return $errors; |
| 1430 | + } |
1464 | 1431 | |
| 1432 | + /** |
| 1433 | + * Check that the user isn't blocked from editting. |
| 1434 | + * @see checkQuickPermissions for parameter information |
| 1435 | + */ |
| 1436 | + private function checkUserBlock( $action, $user, $errors, $doExpensiveQueries, $short ) { |
| 1437 | + if( $short ) { |
| 1438 | + return $errors; |
| 1439 | + } |
| 1440 | + |
| 1441 | + global $wgContLang; |
| 1442 | + global $wgLang; |
| 1443 | + global $wgEmailConfirmToEdit; |
| 1444 | + |
| 1445 | + if ( $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount' ) { |
| 1446 | + $errors[] = array( 'confirmedittext' ); |
| 1447 | + } |
| 1448 | + |
| 1449 | + // Edit blocks should not affect reading. Account creation blocks handled at userlogin. |
| 1450 | + if ( $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this ) ) { |
| 1451 | + $block = $user->mBlock; |
| 1452 | + |
| 1453 | + // This is from OutputPage::blockedPage |
| 1454 | + // Copied at r23888 by werdna |
| 1455 | + |
| 1456 | + $id = $user->blockedBy(); |
| 1457 | + $reason = $user->blockedFor(); |
| 1458 | + if ( $reason == '' ) { |
| 1459 | + $reason = wfMsg( 'blockednoreason' ); |
| 1460 | + } |
| 1461 | + $ip = wfGetIP(); |
| 1462 | + |
| 1463 | + if ( is_numeric( $id ) ) { |
| 1464 | + $name = User::whoIs( $id ); |
| 1465 | + } else { |
| 1466 | + $name = $id; |
| 1467 | + } |
| 1468 | + |
| 1469 | + $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]"; |
| 1470 | + $blockid = $block->mId; |
| 1471 | + $blockExpiry = $user->mBlock->mExpiry; |
| 1472 | + $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW, $user->mBlock->mTimestamp ), true ); |
| 1473 | + if ( $blockExpiry == 'infinity' ) { |
| 1474 | + // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite' |
| 1475 | + $scBlockExpiryOptions = wfMsg( 'ipboptions' ); |
| 1476 | + |
| 1477 | + foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) { |
| 1478 | + if ( strpos( $option, ':' ) == false ) |
| 1479 | + continue; |
| 1480 | + |
| 1481 | + list ( $show, $value ) = explode( ":", $option ); |
| 1482 | + |
| 1483 | + if ( $value == 'infinite' || $value == 'indefinite' ) { |
| 1484 | + $blockExpiry = $show; |
| 1485 | + break; |
| 1486 | + } |
| 1487 | + } |
| 1488 | + } else { |
| 1489 | + $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW, $blockExpiry ), true ); |
| 1490 | + } |
| 1491 | + |
| 1492 | + $intended = $user->mBlock->mAddress; |
| 1493 | + |
| 1494 | + $errors[] = array( ( $block->mAuto ? 'autoblockedtext' : 'blockedtext' ), $link, $reason, $ip, $name, |
| 1495 | + $blockid, $blockExpiry, $intended, $blockTimestamp ); |
| 1496 | + } |
| 1497 | + |
| 1498 | + return $errors; |
| 1499 | + } |
| 1500 | + |
| 1501 | + /** |
| 1502 | + * Can $user perform $action on this page? This is an internal function, |
| 1503 | + * which checks ONLY that previously checked by userCan (i.e. it leaves out |
| 1504 | + * checks on wfReadOnly() and blocks) |
| 1505 | + * |
| 1506 | + * @param $action \type{\string} action that permission needs to be checked for |
| 1507 | + * @param $user \type{User} user to check |
| 1508 | + * @param $doExpensiveQueries \type{\bool} Set this to false to avoid doing unnecessary queries. |
| 1509 | + * @param $short \type{\bool} Set this to true to stop after the first permission error. |
| 1510 | + * @return \type{\array} Array of arrays of the arguments to wfMsg to explain permissions problems. |
| 1511 | + */ |
| 1512 | + protected function getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries = true, $short = false ) { |
| 1513 | + wfProfileIn( __METHOD__ ); |
| 1514 | + |
| 1515 | + $errors = array(); |
| 1516 | + $checks = array( 'checkQuickPermissions', |
| 1517 | + 'checkPermissionHooks', |
| 1518 | + 'checkSpecialsAndNSPermissions', |
| 1519 | + 'checkCSSandJSPermissions', |
| 1520 | + 'checkPageRestrictions', |
| 1521 | + 'checkCascadingSourcesRestrictions', |
| 1522 | + 'checkActionPermissions', |
| 1523 | + 'checkUserBlock' ); |
| 1524 | + |
| 1525 | + while( count( $checks ) > 0 && |
| 1526 | + !( $short && count( $errors ) > 0 ) ) { |
| 1527 | + $method = array_shift( $checks ); |
| 1528 | + $errors = $this->$method( $action, $user, $errors, $doExpensiveQueries, $short ); |
| 1529 | + } |
| 1530 | + |
1465 | 1531 | wfProfileOut( __METHOD__ ); |
1466 | 1532 | return $errors; |
1467 | 1533 | } |
— | — | @@ -1478,7 +1544,7 @@ |
1479 | 1545 | } |
1480 | 1546 | |
1481 | 1547 | // Can't protect pages that exist. |
1482 | | - if ($this->exists()) { |
| 1548 | + if ( $this->exists() ) { |
1483 | 1549 | return false; |
1484 | 1550 | } |
1485 | 1551 | |
— | — | @@ -1503,37 +1569,37 @@ |
1504 | 1570 | * @return boolean true |
1505 | 1571 | */ |
1506 | 1572 | public function updateTitleProtection( $create_perm, $reason, $expiry ) { |
1507 | | - global $wgUser,$wgContLang; |
| 1573 | + global $wgUser, $wgContLang; |
1508 | 1574 | |
1509 | | - if ($create_perm == implode(',',$this->getRestrictions('create')) |
1510 | | - && $expiry == $this->mRestrictionsExpiry['create']) { |
| 1575 | + if ( $create_perm == implode( ',', $this->getRestrictions( 'create' ) ) |
| 1576 | + && $expiry == $this->mRestrictionsExpiry['create'] ) { |
1511 | 1577 | // No change |
1512 | 1578 | return true; |
1513 | 1579 | } |
1514 | 1580 | |
1515 | | - list ($namespace, $title) = array( $this->getNamespace(), $this->getDBkey() ); |
| 1581 | + list ( $namespace, $title ) = array( $this->getNamespace(), $this->getDBkey() ); |
1516 | 1582 | |
1517 | 1583 | $dbw = wfGetDB( DB_MASTER ); |
1518 | 1584 | |
1519 | | - $encodedExpiry = Block::encodeExpiry($expiry, $dbw ); |
| 1585 | + $encodedExpiry = Block::encodeExpiry( $expiry, $dbw ); |
1520 | 1586 | |
1521 | 1587 | $expiry_description = ''; |
1522 | 1588 | if ( $encodedExpiry != 'infinity' ) { |
1523 | | - $expiry_description = ' (' . wfMsgForContent( 'protect-expiring',$wgContLang->timeanddate( $expiry ), |
1524 | | - $wgContLang->date( $expiry ) , $wgContLang->time( $expiry ) ).')'; |
| 1589 | + $expiry_description = ' (' . wfMsgForContent( 'protect-expiring', $wgContLang->timeanddate( $expiry ), |
| 1590 | + $wgContLang->date( $expiry ) , $wgContLang->time( $expiry ) ) . ')'; |
1525 | 1591 | } |
1526 | 1592 | else { |
1527 | | - $expiry_description .= ' (' . wfMsgForContent( 'protect-expiry-indefinite' ).')'; |
| 1593 | + $expiry_description .= ' (' . wfMsgForContent( 'protect-expiry-indefinite' ) . ')'; |
1528 | 1594 | } |
1529 | 1595 | |
1530 | 1596 | # Update protection table |
1531 | | - if ($create_perm != '' ) { |
1532 | | - $dbw->replace( 'protected_titles', array(array('pt_namespace', 'pt_title')), |
| 1597 | + if ( $create_perm != '' ) { |
| 1598 | + $dbw->replace( 'protected_titles', array( array( 'pt_namespace', 'pt_title' ) ), |
1533 | 1599 | array( |
1534 | 1600 | 'pt_namespace' => $namespace, |
1535 | 1601 | 'pt_title' => $title, |
1536 | 1602 | 'pt_create_perm' => $create_perm, |
1537 | | - 'pt_timestamp' => Block::encodeExpiry(wfTimestampNow(), $dbw), |
| 1603 | + 'pt_timestamp' => Block::encodeExpiry( wfTimestampNow(), $dbw ), |
1538 | 1604 | 'pt_expiry' => $encodedExpiry, |
1539 | 1605 | 'pt_user' => $wgUser->getId(), |
1540 | 1606 | 'pt_reason' => $reason, |
— | — | @@ -1544,11 +1610,11 @@ |
1545 | 1611 | 'pt_title' => $title ), __METHOD__ ); |
1546 | 1612 | } |
1547 | 1613 | # Update the protection log |
1548 | | - if( $dbw->affectedRows() ) { |
| 1614 | + if ( $dbw->affectedRows() ) { |
1549 | 1615 | $log = new LogPage( 'protect' ); |
1550 | 1616 | |
1551 | | - if( $create_perm ) { |
1552 | | - $params = array("[create=$create_perm] $expiry_description",''); |
| 1617 | + if ( $create_perm ) { |
| 1618 | + $params = array( "[create=$create_perm] $expiry_description", '' ); |
1553 | 1619 | $log->addEntry( ( isset( $this->mRestrictions['create'] ) && $this->mRestrictions['create'] ) ? 'modify' : 'protect', $this, trim( $reason ), $params ); |
1554 | 1620 | } else { |
1555 | 1621 | $log->addEntry( 'unprotect', $this, $reason ); |
— | — | @@ -1591,21 +1657,21 @@ |
1592 | 1658 | static $useShortcut = null; |
1593 | 1659 | |
1594 | 1660 | # Initialize the $useShortcut boolean, to determine if we can skip quite a bit of code below |
1595 | | - if( is_null( $useShortcut ) ) { |
| 1661 | + if ( is_null( $useShortcut ) ) { |
1596 | 1662 | global $wgRevokePermissions; |
1597 | 1663 | $useShortcut = true; |
1598 | | - if( empty( $wgGroupPermissions['*']['read'] ) ) { |
| 1664 | + if ( empty( $wgGroupPermissions['*']['read'] ) ) { |
1599 | 1665 | # Not a public wiki, so no shortcut |
1600 | 1666 | $useShortcut = false; |
1601 | | - } elseif( !empty( $wgRevokePermissions ) ) { |
| 1667 | + } elseif ( !empty( $wgRevokePermissions ) ) { |
1602 | 1668 | /* |
1603 | 1669 | * Iterate through each group with permissions being revoked (key not included since we don't care |
1604 | 1670 | * what the group name is), then check if the read permission is being revoked. If it is, then |
1605 | 1671 | * we don't use the shortcut below since the user might not be able to read, even though anon |
1606 | 1672 | * reading is allowed. |
1607 | 1673 | */ |
1608 | | - foreach( $wgRevokePermissions as $perms ) { |
1609 | | - if( !empty( $perms['read'] ) ) { |
| 1674 | + foreach ( $wgRevokePermissions as $perms ) { |
| 1675 | + if ( !empty( $perms['read'] ) ) { |
1610 | 1676 | # We might be removing the read right from the user, so no shortcut |
1611 | 1677 | $useShortcut = false; |
1612 | 1678 | break; |
— | — | @@ -1624,7 +1690,7 @@ |
1625 | 1691 | if ( $useShortcut ) |
1626 | 1692 | return true; |
1627 | 1693 | |
1628 | | - if( $wgUser->isAllowed( 'read' ) ) { |
| 1694 | + if ( $wgUser->isAllowed( 'read' ) ) { |
1629 | 1695 | return true; |
1630 | 1696 | } else { |
1631 | 1697 | global $wgWhitelistRead; |
— | — | @@ -1633,14 +1699,14 @@ |
1634 | 1700 | * Always grant access to the login page. |
1635 | 1701 | * Even anons need to be able to log in. |
1636 | 1702 | */ |
1637 | | - if( $this->isSpecial( 'Userlogin' ) || $this->isSpecial( 'Resetpass' ) ) { |
| 1703 | + if ( $this->isSpecial( 'Userlogin' ) || $this->isSpecial( 'Resetpass' ) ) { |
1638 | 1704 | return true; |
1639 | 1705 | } |
1640 | 1706 | |
1641 | 1707 | /** |
1642 | 1708 | * Bail out if there isn't whitelist |
1643 | 1709 | */ |
1644 | | - if( !is_array($wgWhitelistRead) ) { |
| 1710 | + if ( !is_array( $wgWhitelistRead ) ) { |
1645 | 1711 | return false; |
1646 | 1712 | } |
1647 | 1713 | |
— | — | @@ -1650,15 +1716,15 @@ |
1651 | 1717 | $name = $this->getPrefixedText(); |
1652 | 1718 | $dbName = $this->getPrefixedDBKey(); |
1653 | 1719 | // Check with and without underscores |
1654 | | - if( in_array($name,$wgWhitelistRead,true) || in_array($dbName,$wgWhitelistRead,true) ) |
| 1720 | + if ( in_array( $name, $wgWhitelistRead, true ) || in_array( $dbName, $wgWhitelistRead, true ) ) |
1655 | 1721 | return true; |
1656 | 1722 | |
1657 | 1723 | /** |
1658 | 1724 | * Old settings might have the title prefixed with |
1659 | 1725 | * a colon for main-namespace pages |
1660 | 1726 | */ |
1661 | | - if( $this->getNamespace() == NS_MAIN ) { |
1662 | | - if( in_array( ':' . $name, $wgWhitelistRead ) ) |
| 1727 | + if ( $this->getNamespace() == NS_MAIN ) { |
| 1728 | + if ( in_array( ':' . $name, $wgWhitelistRead ) ) |
1663 | 1729 | return true; |
1664 | 1730 | } |
1665 | 1731 | |
— | — | @@ -1666,16 +1732,16 @@ |
1667 | 1733 | * If it's a special page, ditch the subpage bit |
1668 | 1734 | * and check again |
1669 | 1735 | */ |
1670 | | - if( $this->getNamespace() == NS_SPECIAL ) { |
| 1736 | + if ( $this->getNamespace() == NS_SPECIAL ) { |
1671 | 1737 | $name = $this->getDBkey(); |
1672 | | - list( $name, /* $subpage */) = SpecialPage::resolveAliasWithSubpage( $name ); |
| 1738 | + list( $name, /* $subpage */ ) = SpecialPage::resolveAliasWithSubpage( $name ); |
1673 | 1739 | if ( $name === false ) { |
1674 | 1740 | # Invalid special page, but we show standard login required message |
1675 | 1741 | return false; |
1676 | 1742 | } |
1677 | 1743 | |
1678 | 1744 | $pure = SpecialPage::getTitleFor( $name )->getPrefixedText(); |
1679 | | - if( in_array( $pure, $wgWhitelistRead, true ) ) |
| 1745 | + if ( in_array( $pure, $wgWhitelistRead, true ) ) |
1680 | 1746 | return true; |
1681 | 1747 | } |
1682 | 1748 | |
— | — | @@ -1709,7 +1775,7 @@ |
1710 | 1776 | * @return \type{\bool} |
1711 | 1777 | */ |
1712 | 1778 | public function hasSubpages() { |
1713 | | - if( !MWNamespace::hasSubpages( $this->mNamespace ) ) { |
| 1779 | + if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) { |
1714 | 1780 | # Duh |
1715 | 1781 | return false; |
1716 | 1782 | } |
— | — | @@ -1718,12 +1784,12 @@ |
1719 | 1785 | # alone to cache the result. There's no point in having it hanging |
1720 | 1786 | # around uninitialized in every Title object; therefore we only add it |
1721 | 1787 | # if needed and don't declare it statically. |
1722 | | - if( isset( $this->mHasSubpages ) ) { |
| 1788 | + if ( isset( $this->mHasSubpages ) ) { |
1723 | 1789 | return $this->mHasSubpages; |
1724 | 1790 | } |
1725 | 1791 | |
1726 | 1792 | $subpages = $this->getSubpages( 1 ); |
1727 | | - if( $subpages instanceof TitleArray ) |
| 1793 | + if ( $subpages instanceof TitleArray ) |
1728 | 1794 | return $this->mHasSubpages = (bool)$subpages->count(); |
1729 | 1795 | return $this->mHasSubpages = false; |
1730 | 1796 | } |
— | — | @@ -1736,14 +1802,14 @@ |
1737 | 1803 | * doesn't allow subpages |
1738 | 1804 | */ |
1739 | 1805 | public function getSubpages( $limit = -1 ) { |
1740 | | - if( !MWNamespace::hasSubpages( $this->getNamespace() ) ) |
| 1806 | + if ( !MWNamespace::hasSubpages( $this->getNamespace() ) ) |
1741 | 1807 | return array(); |
1742 | 1808 | |
1743 | 1809 | $dbr = wfGetDB( DB_SLAVE ); |
1744 | 1810 | $conds['page_namespace'] = $this->getNamespace(); |
1745 | 1811 | $conds[] = 'page_title ' . $dbr->buildLike( $this->getDBkey() . '/', $dbr->anyString() ); |
1746 | 1812 | $options = array(); |
1747 | | - if( $limit > -1 ) |
| 1813 | + if ( $limit > -1 ) |
1748 | 1814 | $options['LIMIT'] = $limit; |
1749 | 1815 | return $this->mSubpages = TitleArray::newFromResult( |
1750 | 1816 | $dbr->select( 'page', |
— | — | @@ -1771,7 +1837,7 @@ |
1772 | 1838 | * @return \type{\bool} |
1773 | 1839 | */ |
1774 | 1840 | public function isCssJsSubpage() { |
1775 | | - return ( NS_USER == $this->mNamespace and preg_match("/\\/.*\\.(?:css|js)$/", $this->mTextform ) ); |
| 1841 | + return ( NS_USER == $this->mNamespace and preg_match( "/\\/.*\\.(?:css|js)$/", $this->mTextform ) ); |
1776 | 1842 | } |
1777 | 1843 | |
1778 | 1844 | /** |
— | — | @@ -1808,7 +1874,7 @@ |
1809 | 1875 | * @return \type{\bool} |
1810 | 1876 | */ |
1811 | 1877 | public function isCssSubpage() { |
1812 | | - return ( NS_USER == $this->mNamespace && preg_match("/\\/.*\\.css$/", $this->mTextform ) ); |
| 1878 | + return ( NS_USER == $this->mNamespace && preg_match( "/\\/.*\\.css$/", $this->mTextform ) ); |
1813 | 1879 | } |
1814 | 1880 | |
1815 | 1881 | /** |
— | — | @@ -1817,7 +1883,7 @@ |
1818 | 1884 | * @return \type{\bool} |
1819 | 1885 | */ |
1820 | 1886 | public function isJsSubpage() { |
1821 | | - return ( NS_USER == $this->mNamespace && preg_match("/\\/.*\\.js$/", $this->mTextform ) ); |
| 1887 | + return ( NS_USER == $this->mNamespace && preg_match( "/\\/.*\\.js$/", $this->mTextform ) ); |
1822 | 1888 | } |
1823 | 1889 | |
1824 | 1890 | /** |
— | — | @@ -1829,8 +1895,8 @@ |
1830 | 1896 | */ |
1831 | 1897 | public function userCanEditCssSubpage() { |
1832 | 1898 | global $wgUser; |
1833 | | - return ( ( $wgUser->isAllowed('editusercssjs') && $wgUser->isAllowed('editusercss') ) |
1834 | | - || preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform) ); |
| 1899 | + return ( ( $wgUser->isAllowed( 'editusercssjs' ) && $wgUser->isAllowed( 'editusercss' ) ) |
| 1900 | + || preg_match( '/^' . preg_quote( $wgUser->getName(), '/' ) . '\//', $this->mTextform ) ); |
1835 | 1901 | } |
1836 | 1902 | /** |
1837 | 1903 | * Protect js subpages of user pages: can $wgUser edit |
— | — | @@ -1841,8 +1907,8 @@ |
1842 | 1908 | */ |
1843 | 1909 | public function userCanEditJsSubpage() { |
1844 | 1910 | global $wgUser; |
1845 | | - return ( ( $wgUser->isAllowed('editusercssjs') && $wgUser->isAllowed('edituserjs') ) |
1846 | | - || preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform) ); |
| 1911 | + return ( ( $wgUser->isAllowed( 'editusercssjs' ) && $wgUser->isAllowed( 'edituserjs' ) ) |
| 1912 | + || preg_match( '/^' . preg_quote( $wgUser->getName(), '/' ) . '\//', $this->mTextform ) ); |
1847 | 1913 | } |
1848 | 1914 | |
1849 | 1915 | /** |
— | — | @@ -1858,20 +1924,20 @@ |
1859 | 1925 | /** |
1860 | 1926 | * Cascading protection: Get the source of any cascading restrictions on this page. |
1861 | 1927 | * |
1862 | | - * @param $get_pages \type{\bool} Whether or not to retrieve the actual pages |
| 1928 | + * @param $getPages \type{\bool} Whether or not to retrieve the actual pages |
1863 | 1929 | * that the restrictions have come from. |
1864 | 1930 | * @return \type{\arrayof{mixed title array, restriction array}} Array of the Title |
1865 | 1931 | * objects of the pages from which cascading restrictions have come, |
1866 | | - * false for none, or true if such restrictions exist, but $get_pages was not set. |
| 1932 | + * false for none, or true if such restrictions exist, but $getPages was not set. |
1867 | 1933 | * The restriction array is an array of each type, each of which contains a |
1868 | 1934 | * array of unique groups. |
1869 | 1935 | */ |
1870 | | - public function getCascadeProtectionSources( $get_pages = true ) { |
| 1936 | + public function getCascadeProtectionSources( $getPages = true ) { |
1871 | 1937 | $pagerestrictions = array(); |
1872 | 1938 | |
1873 | | - if ( isset( $this->mCascadeSources ) && $get_pages ) { |
| 1939 | + if ( isset( $this->mCascadeSources ) && $getPages ) { |
1874 | 1940 | return array( $this->mCascadeSources, $this->mCascadingRestrictions ); |
1875 | | - } else if ( isset( $this->mHasCascadingRestrictions ) && !$get_pages ) { |
| 1941 | + } else if ( isset( $this->mHasCascadingRestrictions ) && !$getPages ) { |
1876 | 1942 | return array( $this->mHasCascadingRestrictions, $pagerestrictions ); |
1877 | 1943 | } |
1878 | 1944 | |
— | — | @@ -1880,13 +1946,13 @@ |
1881 | 1947 | $dbr = wfGetDB( DB_SLAVE ); |
1882 | 1948 | |
1883 | 1949 | if ( $this->getNamespace() == NS_FILE ) { |
1884 | | - $tables = array ('imagelinks', 'page_restrictions'); |
| 1950 | + $tables = array ( 'imagelinks', 'page_restrictions' ); |
1885 | 1951 | $where_clauses = array( |
1886 | 1952 | 'il_to' => $this->getDBkey(), |
1887 | 1953 | 'il_from=pr_page', |
1888 | 1954 | 'pr_cascade' => 1 ); |
1889 | 1955 | } else { |
1890 | | - $tables = array ('templatelinks', 'page_restrictions'); |
| 1956 | + $tables = array ( 'templatelinks', 'page_restrictions' ); |
1891 | 1957 | $where_clauses = array( |
1892 | 1958 | 'tl_namespace' => $this->getNamespace(), |
1893 | 1959 | 'tl_title' => $this->getDBkey(), |
— | — | @@ -1894,8 +1960,9 @@ |
1895 | 1961 | 'pr_cascade' => 1 ); |
1896 | 1962 | } |
1897 | 1963 | |
1898 | | - if ( $get_pages ) { |
1899 | | - $cols = array('pr_page', 'page_namespace', 'page_title', 'pr_expiry', 'pr_type', 'pr_level' ); |
| 1964 | + if ( $getPages ) { |
| 1965 | + $cols = array( 'pr_page', 'page_namespace', 'page_title', |
| 1966 | + 'pr_expiry', 'pr_type', 'pr_level' ); |
1900 | 1967 | $where_clauses[] = 'page_id=pr_page'; |
1901 | 1968 | $tables[] = 'page'; |
1902 | 1969 | } else { |
— | — | @@ -1904,18 +1971,18 @@ |
1905 | 1972 | |
1906 | 1973 | $res = $dbr->select( $tables, $cols, $where_clauses, __METHOD__ ); |
1907 | 1974 | |
1908 | | - $sources = $get_pages ? array() : false; |
| 1975 | + $sources = $getPages ? array() : false; |
1909 | 1976 | $now = wfTimestampNow(); |
1910 | 1977 | $purgeExpired = false; |
1911 | 1978 | |
1912 | | - foreach( $res as $row ) { |
| 1979 | + foreach ( $res as $row ) { |
1913 | 1980 | $expiry = Block::decodeExpiry( $row->pr_expiry ); |
1914 | | - if( $expiry > $now ) { |
1915 | | - if ($get_pages) { |
| 1981 | + if ( $expiry > $now ) { |
| 1982 | + if ( $getPages ) { |
1916 | 1983 | $page_id = $row->pr_page; |
1917 | 1984 | $page_ns = $row->page_namespace; |
1918 | 1985 | $page_title = $row->page_title; |
1919 | | - $sources[$page_id] = Title::makeTitle($page_ns, $page_title); |
| 1986 | + $sources[$page_id] = Title::makeTitle( $page_ns, $page_title ); |
1920 | 1987 | # Add groups needed for each restriction type if its not already there |
1921 | 1988 | # Make sure this restriction type still exists |
1922 | 1989 | |
— | — | @@ -1923,9 +1990,9 @@ |
1924 | 1991 | $pagerestrictions[$row->pr_type] = array(); |
1925 | 1992 | } |
1926 | 1993 | |
1927 | | - if ( isset($pagerestrictions[$row->pr_type]) && |
1928 | | - !in_array($row->pr_level, $pagerestrictions[$row->pr_type]) ) { |
1929 | | - $pagerestrictions[$row->pr_type][]=$row->pr_level; |
| 1994 | + if ( isset( $pagerestrictions[$row->pr_type] ) && |
| 1995 | + !in_array( $row->pr_level, $pagerestrictions[$row->pr_type] ) ) { |
| 1996 | + $pagerestrictions[$row->pr_type][] = $row->pr_level; |
1930 | 1997 | } |
1931 | 1998 | } else { |
1932 | 1999 | $sources = true; |
— | — | @@ -1935,18 +2002,19 @@ |
1936 | 2003 | $purgeExpired = true; |
1937 | 2004 | } |
1938 | 2005 | } |
1939 | | - if( $purgeExpired ) { |
| 2006 | + if ( $purgeExpired ) { |
1940 | 2007 | Title::purgeExpiredRestrictions(); |
1941 | 2008 | } |
1942 | 2009 | |
1943 | 2010 | wfProfileOut( __METHOD__ ); |
1944 | 2011 | |
1945 | | - if ( $get_pages ) { |
| 2012 | + if ( $getPages ) { |
1946 | 2013 | $this->mCascadeSources = $sources; |
1947 | 2014 | $this->mCascadingRestrictions = $pagerestrictions; |
1948 | 2015 | } else { |
1949 | 2016 | $this->mHasCascadingRestrictions = $sources; |
1950 | 2017 | } |
| 2018 | + |
1951 | 2019 | return array( $sources, $pagerestrictions ); |
1952 | 2020 | } |
1953 | 2021 | |
— | — | @@ -1956,7 +2024,7 @@ |
1957 | 2025 | * @return Boolean |
1958 | 2026 | */ |
1959 | 2027 | function areRestrictionsCascading() { |
1960 | | - if (!$this->mRestrictionsLoaded) { |
| 2028 | + if ( !$this->mRestrictionsLoaded ) { |
1961 | 2029 | $this->loadRestrictions(); |
1962 | 2030 | } |
1963 | 2031 | |
— | — | @@ -1974,7 +2042,7 @@ |
1975 | 2043 | $rows = array(); |
1976 | 2044 | $dbr = wfGetDB( DB_SLAVE ); |
1977 | 2045 | |
1978 | | - while( $row = $dbr->fetchObject( $res ) ) { |
| 2046 | + while ( $row = $dbr->fetchObject( $res ) ) { |
1979 | 2047 | $rows[] = $row; |
1980 | 2048 | } |
1981 | 2049 | |
— | — | @@ -1994,9 +2062,9 @@ |
1995 | 2063 | |
1996 | 2064 | $restrictionTypes = $this->getRestrictionTypes(); |
1997 | 2065 | |
1998 | | - foreach( $restrictionTypes as $type ){ |
| 2066 | + foreach ( $restrictionTypes as $type ) { |
1999 | 2067 | $this->mRestrictions[$type] = array(); |
2000 | | - $this->mRestrictionsExpiry[$type] = Block::decodeExpiry(''); |
| 2068 | + $this->mRestrictionsExpiry[$type] = Block::decodeExpiry( '' ); |
2001 | 2069 | } |
2002 | 2070 | |
2003 | 2071 | $this->mCascadeRestriction = false; |
— | — | @@ -2008,11 +2076,11 @@ |
2009 | 2077 | array( 'page_id' => $this->getArticleId() ), __METHOD__ ); |
2010 | 2078 | } |
2011 | 2079 | |
2012 | | - if ($oldFashionedRestrictions != '') { |
| 2080 | + if ( $oldFashionedRestrictions != '' ) { |
2013 | 2081 | |
2014 | | - foreach( explode( ':', trim( $oldFashionedRestrictions ) ) as $restrict ) { |
| 2082 | + foreach ( explode( ':', trim( $oldFashionedRestrictions ) ) as $restrict ) { |
2015 | 2083 | $temp = explode( '=', trim( $restrict ) ); |
2016 | | - if(count($temp) == 1) { |
| 2084 | + if ( count( $temp ) == 1 ) { |
2017 | 2085 | // old old format should be treated as edit/move restriction |
2018 | 2086 | $this->mRestrictions['edit'] = explode( ',', trim( $temp[0] ) ); |
2019 | 2087 | $this->mRestrictions['move'] = explode( ',', trim( $temp[0] ) ); |
— | — | @@ -2025,17 +2093,17 @@ |
2026 | 2094 | |
2027 | 2095 | } |
2028 | 2096 | |
2029 | | - if( count($rows) ) { |
| 2097 | + if ( count( $rows ) ) { |
2030 | 2098 | # Current system - load second to make them override. |
2031 | 2099 | $now = wfTimestampNow(); |
2032 | 2100 | $purgeExpired = false; |
2033 | 2101 | |
2034 | | - foreach( $rows as $row ) { |
| 2102 | + foreach ( $rows as $row ) { |
2035 | 2103 | # Cycle through all the restrictions. |
2036 | 2104 | |
2037 | 2105 | // Don't take care of restrictions types that aren't allowed |
2038 | 2106 | |
2039 | | - if( !in_array( $row->pr_type, $restrictionTypes ) ) |
| 2107 | + if ( !in_array( $row->pr_type, $restrictionTypes ) ) |
2040 | 2108 | continue; |
2041 | 2109 | |
2042 | 2110 | // This code should be refactored, now that it's being used more generally, |
— | — | @@ -2054,7 +2122,7 @@ |
2055 | 2123 | } |
2056 | 2124 | } |
2057 | 2125 | |
2058 | | - if( $purgeExpired ) { |
| 2126 | + if ( $purgeExpired ) { |
2059 | 2127 | Title::purgeExpiredRestrictions(); |
2060 | 2128 | } |
2061 | 2129 | } |
— | — | @@ -2069,8 +2137,8 @@ |
2070 | 2138 | * restrictions from page table (pre 1.10) |
2071 | 2139 | */ |
2072 | 2140 | public function loadRestrictions( $oldFashionedRestrictions = null ) { |
2073 | | - if( !$this->mRestrictionsLoaded ) { |
2074 | | - if ($this->exists()) { |
| 2141 | + if ( !$this->mRestrictionsLoaded ) { |
| 2142 | + if ( $this->exists() ) { |
2075 | 2143 | $dbr = wfGetDB( DB_SLAVE ); |
2076 | 2144 | |
2077 | 2145 | $res = $dbr->select( 'page_restrictions', '*', |
— | — | @@ -2080,19 +2148,19 @@ |
2081 | 2149 | } else { |
2082 | 2150 | $title_protection = $this->getTitleProtection(); |
2083 | 2151 | |
2084 | | - if ($title_protection) { |
| 2152 | + if ( $title_protection ) { |
2085 | 2153 | $now = wfTimestampNow(); |
2086 | | - $expiry = Block::decodeExpiry($title_protection['pt_expiry']); |
| 2154 | + $expiry = Block::decodeExpiry( $title_protection['pt_expiry'] ); |
2087 | 2155 | |
2088 | | - if (!$expiry || $expiry > $now) { |
| 2156 | + if ( !$expiry || $expiry > $now ) { |
2089 | 2157 | // Apply the restrictions |
2090 | 2158 | $this->mRestrictionsExpiry['create'] = $expiry; |
2091 | | - $this->mRestrictions['create'] = explode(',', trim($title_protection['pt_create_perm']) ); |
| 2159 | + $this->mRestrictions['create'] = explode( ',', trim( $title_protection['pt_create_perm'] ) ); |
2092 | 2160 | } else { // Get rid of the old restrictions |
2093 | 2161 | Title::purgeExpiredRestrictions(); |
2094 | 2162 | } |
2095 | 2163 | } else { |
2096 | | - $this->mRestrictionsExpiry['create'] = Block::decodeExpiry(''); |
| 2164 | + $this->mRestrictionsExpiry['create'] = Block::decodeExpiry( '' ); |
2097 | 2165 | } |
2098 | 2166 | $this->mRestrictionsLoaded = true; |
2099 | 2167 | } |
— | — | @@ -2120,7 +2188,7 @@ |
2121 | 2189 | * @return \type{\arrayof{\string}} the array of groups allowed to edit this article |
2122 | 2190 | */ |
2123 | 2191 | public function getRestrictions( $action ) { |
2124 | | - if( !$this->mRestrictionsLoaded ) { |
| 2192 | + if ( !$this->mRestrictionsLoaded ) { |
2125 | 2193 | $this->loadRestrictions(); |
2126 | 2194 | } |
2127 | 2195 | return isset( $this->mRestrictions[$action] ) |
— | — | @@ -2135,7 +2203,7 @@ |
2136 | 2204 | * or not protected at all, or false if the action is not recognised. |
2137 | 2205 | */ |
2138 | 2206 | public function getRestrictionExpiry( $action ) { |
2139 | | - if( !$this->mRestrictionsLoaded ) { |
| 2207 | + if ( !$this->mRestrictionsLoaded ) { |
2140 | 2208 | $this->loadRestrictions(); |
2141 | 2209 | } |
2142 | 2210 | return isset( $this->mRestrictionsExpiry[$action] ) ? $this->mRestrictionsExpiry[$action] : false; |
— | — | @@ -2147,7 +2215,7 @@ |
2148 | 2216 | * @return \type{\int} the number of archived revisions |
2149 | 2217 | */ |
2150 | 2218 | public function isDeleted() { |
2151 | | - if( $this->getNamespace() < 0 ) { |
| 2219 | + if ( $this->getNamespace() < 0 ) { |
2152 | 2220 | $n = 0; |
2153 | 2221 | } else { |
2154 | 2222 | $dbr = wfGetDB( DB_SLAVE ); |
— | — | @@ -2155,7 +2223,7 @@ |
2156 | 2224 | array( 'ar_namespace' => $this->getNamespace(), 'ar_title' => $this->getDBkey() ), |
2157 | 2225 | __METHOD__ |
2158 | 2226 | ); |
2159 | | - if( $this->getNamespace() == NS_FILE ) { |
| 2227 | + if ( $this->getNamespace() == NS_FILE ) { |
2160 | 2228 | $n += $dbr->selectField( 'filearchive', 'COUNT(*)', |
2161 | 2229 | array( 'fa_name' => $this->getDBkey() ), |
2162 | 2230 | __METHOD__ |
— | — | @@ -2171,7 +2239,7 @@ |
2172 | 2240 | * @return Boolean |
2173 | 2241 | */ |
2174 | 2242 | public function isDeletedQuick() { |
2175 | | - if( $this->getNamespace() < 0 ) { |
| 2243 | + if ( $this->getNamespace() < 0 ) { |
2176 | 2244 | return false; |
2177 | 2245 | } |
2178 | 2246 | $dbr = wfGetDB( DB_SLAVE ); |
— | — | @@ -2179,7 +2247,7 @@ |
2180 | 2248 | array( 'ar_namespace' => $this->getNamespace(), 'ar_title' => $this->getDBkey() ), |
2181 | 2249 | __METHOD__ |
2182 | 2250 | ); |
2183 | | - if( !$deleted && $this->getNamespace() == NS_FILE ) { |
| 2251 | + if ( !$deleted && $this->getNamespace() == NS_FILE ) { |
2184 | 2252 | $deleted = (bool)$dbr->selectField( 'filearchive', '1', |
2185 | 2253 | array( 'fa_name' => $this->getDBkey() ), |
2186 | 2254 | __METHOD__ |
— | — | @@ -2197,17 +2265,17 @@ |
2198 | 2266 | * @return \type{\int} the ID |
2199 | 2267 | */ |
2200 | 2268 | public function getArticleID( $flags = 0 ) { |
2201 | | - if( $this->getNamespace() < 0 ) { |
| 2269 | + if ( $this->getNamespace() < 0 ) { |
2202 | 2270 | return $this->mArticleID = 0; |
2203 | 2271 | } |
2204 | 2272 | $linkCache = LinkCache::singleton(); |
2205 | | - if( $flags & GAID_FOR_UPDATE ) { |
| 2273 | + if ( $flags & GAID_FOR_UPDATE ) { |
2206 | 2274 | $oldUpdate = $linkCache->forUpdate( true ); |
2207 | 2275 | $linkCache->clearLink( $this ); |
2208 | 2276 | $this->mArticleID = $linkCache->addLinkObj( $this ); |
2209 | 2277 | $linkCache->forUpdate( $oldUpdate ); |
2210 | 2278 | } else { |
2211 | | - if( -1 == $this->mArticleID ) { |
| 2279 | + if ( -1 == $this->mArticleID ) { |
2212 | 2280 | $this->mArticleID = $linkCache->addLinkObj( $this ); |
2213 | 2281 | } |
2214 | 2282 | } |
— | — | @@ -2222,10 +2290,10 @@ |
2223 | 2291 | * @return \type{\bool} |
2224 | 2292 | */ |
2225 | 2293 | public function isRedirect( $flags = 0 ) { |
2226 | | - if( !is_null($this->mRedirect) ) |
| 2294 | + if ( !is_null( $this->mRedirect ) ) |
2227 | 2295 | return $this->mRedirect; |
2228 | 2296 | # Calling getArticleID() loads the field from cache as needed |
2229 | | - if( !$this->getArticleID($flags) ) { |
| 2297 | + if ( !$this->getArticleID( $flags ) ) { |
2230 | 2298 | return $this->mRedirect = false; |
2231 | 2299 | } |
2232 | 2300 | $linkCache = LinkCache::singleton(); |
— | — | @@ -2242,10 +2310,10 @@ |
2243 | 2311 | * @return \type{\bool} |
2244 | 2312 | */ |
2245 | 2313 | public function getLength( $flags = 0 ) { |
2246 | | - if( $this->mLength != -1 ) |
| 2314 | + if ( $this->mLength != -1 ) |
2247 | 2315 | return $this->mLength; |
2248 | 2316 | # Calling getArticleID() loads the field from cache as needed |
2249 | | - if( !$this->getArticleID($flags) ) { |
| 2317 | + if ( !$this->getArticleID( $flags ) ) { |
2250 | 2318 | return $this->mLength = 0; |
2251 | 2319 | } |
2252 | 2320 | $linkCache = LinkCache::singleton(); |
— | — | @@ -2261,10 +2329,10 @@ |
2262 | 2330 | * @return \type{\int} or false if the page doesn't exist |
2263 | 2331 | */ |
2264 | 2332 | public function getLatestRevID( $flags = 0 ) { |
2265 | | - if( $this->mLatestID !== false ) |
| 2333 | + if ( $this->mLatestID !== false ) |
2266 | 2334 | return $this->mLatestID; |
2267 | 2335 | |
2268 | | - $db = ($flags & GAID_FOR_UPDATE) ? wfGetDB(DB_MASTER) : wfGetDB(DB_SLAVE); |
| 2336 | + $db = ( $flags & GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); |
2269 | 2337 | $this->mLatestID = (int)$db->selectField( |
2270 | 2338 | 'page', 'page_latest', $this->pageCond(), __METHOD__ ); |
2271 | 2339 | return $this->mLatestID; |
— | — | @@ -2302,7 +2370,7 @@ |
2303 | 2371 | * @return \type{\bool} true if the update succeded |
2304 | 2372 | */ |
2305 | 2373 | public function invalidateCache() { |
2306 | | - if( wfReadOnly() ) { |
| 2374 | + if ( wfReadOnly() ) { |
2307 | 2375 | return; |
2308 | 2376 | } |
2309 | 2377 | $dbw = wfGetDB( DB_MASTER ); |
— | — | @@ -2343,7 +2411,7 @@ |
2344 | 2412 | */ |
2345 | 2413 | static function getTitleInvalidRegex() { |
2346 | 2414 | static $rxTc = false; |
2347 | | - if( !$rxTc ) { |
| 2415 | + if ( !$rxTc ) { |
2348 | 2416 | # Matching titles will be held as illegal. |
2349 | 2417 | $rxTc = '/' . |
2350 | 2418 | # Any character not allowed is forbidden... |
— | — | @@ -2416,7 +2484,7 @@ |
2417 | 2485 | return false; |
2418 | 2486 | } |
2419 | 2487 | |
2420 | | - if( false !== strpos( $dbkey, UTF8_REPLACEMENT ) ) { |
| 2488 | + if ( false !== strpos( $dbkey, UTF8_REPLACEMENT ) ) { |
2421 | 2489 | # Contained illegal UTF-8 sequences or forbidden Unicode chars. |
2422 | 2490 | return false; |
2423 | 2491 | } |
— | — | @@ -2425,7 +2493,7 @@ |
2426 | 2494 | |
2427 | 2495 | # Initial colon indicates main namespace rather than specified default |
2428 | 2496 | # but should not create invalid {ns,title} pairs such as {0,Project:Foo} |
2429 | | - if ( ':' == $dbkey{0} ) { |
| 2497 | + if ( ':' == $dbkey { 0 } ) { |
2430 | 2498 | $this->mNamespace = NS_MAIN; |
2431 | 2499 | $dbkey = substr( $dbkey, 1 ); # remove the colon but continue processing |
2432 | 2500 | $dbkey = trim( $dbkey, '_' ); # remove any subsequent whitespace |
— | — | @@ -2443,14 +2511,14 @@ |
2444 | 2512 | $dbkey = $m[2]; |
2445 | 2513 | $this->mNamespace = $ns; |
2446 | 2514 | # For Talk:X pages, check if X has a "namespace" prefix |
2447 | | - if( $ns == NS_TALK && preg_match( $prefixRegexp, $dbkey, $x ) ) { |
2448 | | - if( $wgContLang->getNsIndex( $x[1] ) ) |
| 2515 | + if ( $ns == NS_TALK && preg_match( $prefixRegexp, $dbkey, $x ) ) { |
| 2516 | + if ( $wgContLang->getNsIndex( $x[1] ) ) |
2449 | 2517 | return false; # Disallow Talk:File:x type titles... |
2450 | | - else if( Interwiki::isValidInterwiki( $x[1] ) ) |
| 2518 | + else if ( Interwiki::isValidInterwiki( $x[1] ) ) |
2451 | 2519 | return false; # Disallow Talk:Interwiki:x type titles... |
2452 | 2520 | } |
2453 | | - } elseif( Interwiki::isValidInterwiki( $p ) ) { |
2454 | | - if( !$firstPass ) { |
| 2521 | + } elseif ( Interwiki::isValidInterwiki( $p ) ) { |
| 2522 | + if ( !$firstPass ) { |
2455 | 2523 | # Can't make a local interwiki link to an interwiki link. |
2456 | 2524 | # That's just crazy! |
2457 | 2525 | return false; |
— | — | @@ -2462,7 +2530,7 @@ |
2463 | 2531 | |
2464 | 2532 | # Redundant interwiki prefix to the local wiki |
2465 | 2533 | if ( 0 == strcasecmp( $this->mInterwiki, $wgLocalInterwiki ) ) { |
2466 | | - if( $dbkey == '' ) { |
| 2534 | + if ( $dbkey == '' ) { |
2467 | 2535 | # Can't have an empty self-link |
2468 | 2536 | return false; |
2469 | 2537 | } |
— | — | @@ -2483,7 +2551,7 @@ |
2484 | 2552 | # then let the colon expression be part of the title. |
2485 | 2553 | } |
2486 | 2554 | break; |
2487 | | - } while( true ); |
| 2555 | + } while ( true ); |
2488 | 2556 | |
2489 | 2557 | # We already know that some pages won't be in the database! |
2490 | 2558 | # |
— | — | @@ -2501,7 +2569,7 @@ |
2502 | 2570 | |
2503 | 2571 | # Reject illegal characters. |
2504 | 2572 | # |
2505 | | - if( preg_match( $rxTc, $dbkey ) ) { |
| 2573 | + if ( preg_match( $rxTc, $dbkey ) ) { |
2506 | 2574 | return false; |
2507 | 2575 | } |
2508 | 2576 | |
— | — | @@ -2525,7 +2593,7 @@ |
2526 | 2594 | /** |
2527 | 2595 | * Magic tilde sequences? Nu-uh! |
2528 | 2596 | */ |
2529 | | - if( strpos( $dbkey, '~~~' ) !== false ) { |
| 2597 | + if ( strpos( $dbkey, '~~~' ) !== false ) { |
2530 | 2598 | return false; |
2531 | 2599 | } |
2532 | 2600 | |
— | — | @@ -2551,7 +2619,7 @@ |
2552 | 2620 | * site might be case-sensitive. |
2553 | 2621 | */ |
2554 | 2622 | $this->mUserCaseDBKey = $dbkey; |
2555 | | - if( $this->mInterwiki == '') { |
| 2623 | + if ( $this->mInterwiki == '' ) { |
2556 | 2624 | $dbkey = self::capitalize( $dbkey, $this->mNamespace ); |
2557 | 2625 | } |
2558 | 2626 | |
— | — | @@ -2560,7 +2628,7 @@ |
2561 | 2629 | * "empty" local links can only be self-links |
2562 | 2630 | * with a fragment identifier. |
2563 | 2631 | */ |
2564 | | - if( $dbkey == '' && |
| 2632 | + if ( $dbkey == '' && |
2565 | 2633 | $this->mInterwiki == '' && |
2566 | 2634 | $this->mNamespace != NS_MAIN ) { |
2567 | 2635 | return false; |
— | — | @@ -2571,10 +2639,10 @@ |
2572 | 2640 | // there are numerous ways to present the same IP. Having sp:contribs scan |
2573 | 2641 | // them all is silly and having some show the edits and others not is |
2574 | 2642 | // inconsistent. Same for talk/userpages. Keep them normalized instead. |
2575 | | - $dbkey = ($this->mNamespace == NS_USER || $this->mNamespace == NS_USER_TALK) ? |
| 2643 | + $dbkey = ( $this->mNamespace == NS_USER || $this->mNamespace == NS_USER_TALK ) ? |
2576 | 2644 | IP::sanitizeIP( $dbkey ) : $dbkey; |
2577 | 2645 | // Any remaining initial :s are illegal. |
2578 | | - if ( $dbkey !== '' && ':' == $dbkey{0} ) { |
| 2646 | + if ( $dbkey !== '' && ':' == $dbkey { 0 } ) { |
2579 | 2647 | return false; |
2580 | 2648 | } |
2581 | 2649 | |
— | — | @@ -2619,7 +2687,7 @@ |
2620 | 2688 | public function getSubjectPage() { |
2621 | 2689 | // Is this the same title? |
2622 | 2690 | $subjectNS = MWNamespace::getSubject( $this->getNamespace() ); |
2623 | | - if( $this->getNamespace() == $subjectNS ) { |
| 2691 | + if ( $this->getNamespace() == $subjectNS ) { |
2624 | 2692 | return $this; |
2625 | 2693 | } |
2626 | 2694 | return Title::makeTitle( $subjectNS, $this->getDBkey() ); |
— | — | @@ -2657,7 +2725,7 @@ |
2658 | 2726 | |
2659 | 2727 | $retVal = array(); |
2660 | 2728 | if ( $db->numRows( $res ) ) { |
2661 | | - foreach( $res as $row ) { |
| 2729 | + foreach ( $res as $row ) { |
2662 | 2730 | if ( $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title ) ) { |
2663 | 2731 | $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect ); |
2664 | 2732 | $retVal[] = $titleObj; |
— | — | @@ -2712,7 +2780,7 @@ |
2713 | 2781 | ); |
2714 | 2782 | |
2715 | 2783 | $retVal = array(); |
2716 | | - foreach( $res as $row ) { |
| 2784 | + foreach ( $res as $row ) { |
2717 | 2785 | $retVal[] = Title::makeTitle( $row->pl_namespace, $row->pl_title ); |
2718 | 2786 | } |
2719 | 2787 | return $retVal; |
— | — | @@ -2734,11 +2802,11 @@ |
2735 | 2803 | ); |
2736 | 2804 | |
2737 | 2805 | // purge variant urls as well |
2738 | | - if($wgContLang->hasVariants()){ |
| 2806 | + if ( $wgContLang->hasVariants() ) { |
2739 | 2807 | $variants = $wgContLang->getVariants(); |
2740 | | - foreach($variants as $vCode){ |
2741 | | - if($vCode==$wgContLang->getCode()) continue; // we don't want default variant |
2742 | | - $urls[] = $this->getInternalURL('',$vCode); |
| 2808 | + foreach ( $variants as $vCode ) { |
| 2809 | + if ( $vCode == $wgContLang->getCode() ) continue; // we don't want default variant |
| 2810 | + $urls[] = $this->getInternalURL( '', $vCode ); |
2743 | 2811 | } |
2744 | 2812 | } |
2745 | 2813 | |
— | — | @@ -2781,52 +2849,52 @@ |
2782 | 2850 | global $wgUser; |
2783 | 2851 | |
2784 | 2852 | $errors = array(); |
2785 | | - if( !$nt ) { |
| 2853 | + if ( !$nt ) { |
2786 | 2854 | // Normally we'd add this to $errors, but we'll get |
2787 | 2855 | // lots of syntax errors if $nt is not an object |
2788 | | - return array(array('badtitletext')); |
| 2856 | + return array( array( 'badtitletext' ) ); |
2789 | 2857 | } |
2790 | | - if( $this->equals( $nt ) ) { |
2791 | | - $errors[] = array('selfmove'); |
| 2858 | + if ( $this->equals( $nt ) ) { |
| 2859 | + $errors[] = array( 'selfmove' ); |
2792 | 2860 | } |
2793 | | - if( !$this->isMovable() ) { |
| 2861 | + if ( !$this->isMovable() ) { |
2794 | 2862 | $errors[] = array( 'immobile-source-namespace', $this->getNsText() ); |
2795 | 2863 | } |
2796 | 2864 | if ( $nt->getInterwiki() != '' ) { |
2797 | 2865 | $errors[] = array( 'immobile-target-namespace-iw' ); |
2798 | 2866 | } |
2799 | 2867 | if ( !$nt->isMovable() ) { |
2800 | | - $errors[] = array('immobile-target-namespace', $nt->getNsText() ); |
| 2868 | + $errors[] = array( 'immobile-target-namespace', $nt->getNsText() ); |
2801 | 2869 | } |
2802 | 2870 | |
2803 | 2871 | $oldid = $this->getArticleID(); |
2804 | 2872 | $newid = $nt->getArticleID(); |
2805 | 2873 | |
2806 | 2874 | if ( strlen( $nt->getDBkey() ) < 1 ) { |
2807 | | - $errors[] = array('articleexists'); |
| 2875 | + $errors[] = array( 'articleexists' ); |
2808 | 2876 | } |
2809 | 2877 | if ( ( $this->getDBkey() == '' ) || |
2810 | 2878 | ( !$oldid ) || |
2811 | 2879 | ( $nt->getDBkey() == '' ) ) { |
2812 | | - $errors[] = array('badarticleerror'); |
| 2880 | + $errors[] = array( 'badarticleerror' ); |
2813 | 2881 | } |
2814 | 2882 | |
2815 | 2883 | // Image-specific checks |
2816 | | - if( $this->getNamespace() == NS_FILE ) { |
| 2884 | + if ( $this->getNamespace() == NS_FILE ) { |
2817 | 2885 | $file = wfLocalFile( $this ); |
2818 | | - if( $file->exists() ) { |
2819 | | - if( $nt->getNamespace() != NS_FILE ) { |
2820 | | - $errors[] = array('imagenocrossnamespace'); |
| 2886 | + if ( $file->exists() ) { |
| 2887 | + if ( $nt->getNamespace() != NS_FILE ) { |
| 2888 | + $errors[] = array( 'imagenocrossnamespace' ); |
2821 | 2889 | } |
2822 | | - if( $nt->getText() != wfStripIllegalFilenameChars( $nt->getText() ) ) { |
2823 | | - $errors[] = array('imageinvalidfilename'); |
| 2890 | + if ( $nt->getText() != wfStripIllegalFilenameChars( $nt->getText() ) ) { |
| 2891 | + $errors[] = array( 'imageinvalidfilename' ); |
2824 | 2892 | } |
2825 | | - if( !File::checkExtensionCompatibility( $file, $nt->getDBkey() ) ) { |
2826 | | - $errors[] = array('imagetypemismatch'); |
| 2893 | + if ( !File::checkExtensionCompatibility( $file, $nt->getDBkey() ) ) { |
| 2894 | + $errors[] = array( 'imagetypemismatch' ); |
2827 | 2895 | } |
2828 | 2896 | } |
2829 | 2897 | $destfile = wfLocalFile( $nt ); |
2830 | | - if( !$wgUser->isAllowed( 'reupload-shared' ) && !$destfile->exists() && wfFindFile( $nt ) ) { |
| 2898 | + if ( !$wgUser->isAllowed( 'reupload-shared' ) && !$destfile->exists() && wfFindFile( $nt ) ) { |
2831 | 2899 | $errors[] = array( 'file-exists-sharedrepo' ); |
2832 | 2900 | } |
2833 | 2901 | |
— | — | @@ -2834,21 +2902,21 @@ |
2835 | 2903 | |
2836 | 2904 | if ( $auth ) { |
2837 | 2905 | $errors = wfMergeErrorArrays( $errors, |
2838 | | - $this->getUserPermissionsErrors('move', $wgUser), |
2839 | | - $this->getUserPermissionsErrors('edit', $wgUser), |
2840 | | - $nt->getUserPermissionsErrors('move-target', $wgUser), |
2841 | | - $nt->getUserPermissionsErrors('edit', $wgUser) ); |
| 2906 | + $this->getUserPermissionsErrors( 'move', $wgUser ), |
| 2907 | + $this->getUserPermissionsErrors( 'edit', $wgUser ), |
| 2908 | + $nt->getUserPermissionsErrors( 'move-target', $wgUser ), |
| 2909 | + $nt->getUserPermissionsErrors( 'edit', $wgUser ) ); |
2842 | 2910 | } |
2843 | 2911 | |
2844 | 2912 | $match = EditPage::matchSummarySpamRegex( $reason ); |
2845 | | - if( $match !== false ) { |
| 2913 | + if ( $match !== false ) { |
2846 | 2914 | // This is kind of lame, won't display nice |
2847 | | - $errors[] = array('spamprotectiontext'); |
| 2915 | + $errors[] = array( 'spamprotectiontext' ); |
2848 | 2916 | } |
2849 | 2917 | |
2850 | 2918 | $err = null; |
2851 | | - if( !wfRunHooks( 'AbortMove', array( $this, $nt, $wgUser, &$err, $reason ) ) ) { |
2852 | | - $errors[] = array('hookaborted', $err); |
| 2919 | + if ( !wfRunHooks( 'AbortMove', array( $this, $nt, $wgUser, &$err, $reason ) ) ) { |
| 2920 | + $errors[] = array( 'hookaborted', $err ); |
2853 | 2921 | } |
2854 | 2922 | |
2855 | 2923 | # The move is allowed only if (1) the target doesn't exist, or |
— | — | @@ -2857,16 +2925,16 @@ |
2858 | 2926 | |
2859 | 2927 | if ( 0 != $newid ) { # Target exists; check for validity |
2860 | 2928 | if ( ! $this->isValidMoveTarget( $nt ) ) { |
2861 | | - $errors[] = array('articleexists'); |
| 2929 | + $errors[] = array( 'articleexists' ); |
2862 | 2930 | } |
2863 | 2931 | } else { |
2864 | 2932 | $tp = $nt->getTitleProtection(); |
2865 | 2933 | $right = ( $tp['pt_create_perm'] == 'sysop' ) ? 'protect' : $tp['pt_create_perm']; |
2866 | 2934 | if ( $tp and !$wgUser->isAllowed( $right ) ) { |
2867 | | - $errors[] = array('cantmove-titleprotected'); |
| 2935 | + $errors[] = array( 'cantmove-titleprotected' ); |
2868 | 2936 | } |
2869 | 2937 | } |
2870 | | - if(empty($errors)) |
| 2938 | + if ( empty( $errors ) ) |
2871 | 2939 | return true; |
2872 | 2940 | return $errors; |
2873 | 2941 | } |
— | — | @@ -2884,17 +2952,17 @@ |
2885 | 2953 | */ |
2886 | 2954 | public function moveTo( &$nt, $auth = true, $reason = '', $createRedirect = true ) { |
2887 | 2955 | $err = $this->isValidMoveOperation( $nt, $auth, $reason ); |
2888 | | - if( is_array( $err ) ) { |
| 2956 | + if ( is_array( $err ) ) { |
2889 | 2957 | return $err; |
2890 | 2958 | } |
2891 | 2959 | |
2892 | 2960 | // If it is a file, move it first. It is done before all other moving stuff is done because it's hard to revert |
2893 | 2961 | $dbw = wfGetDB( DB_MASTER ); |
2894 | | - if( $this->getNamespace() == NS_FILE ) { |
| 2962 | + if ( $this->getNamespace() == NS_FILE ) { |
2895 | 2963 | $file = wfLocalFile( $this ); |
2896 | | - if( $file->exists() ) { |
| 2964 | + if ( $file->exists() ) { |
2897 | 2965 | $status = $file->move( $nt ); |
2898 | | - if( !$status->isOk() ) { |
| 2966 | + if ( !$status->isOk() ) { |
2899 | 2967 | return $status->getErrorsArray(); |
2900 | 2968 | } |
2901 | 2969 | } |
— | — | @@ -2902,15 +2970,15 @@ |
2903 | 2971 | |
2904 | 2972 | $pageid = $this->getArticleID(); |
2905 | 2973 | $protected = $this->isProtected(); |
2906 | | - if( $nt->exists() ) { |
| 2974 | + if ( $nt->exists() ) { |
2907 | 2975 | $err = $this->moveOverExistingRedirect( $nt, $reason, $createRedirect ); |
2908 | | - $pageCountChange = ($createRedirect ? 0 : -1); |
| 2976 | + $pageCountChange = ( $createRedirect ? 0 : -1 ); |
2909 | 2977 | } else { # Target didn't exist, do normal move. |
2910 | 2978 | $err = $this->moveToNewTitle( $nt, $reason, $createRedirect ); |
2911 | | - $pageCountChange = ($createRedirect ? 1 : 0); |
| 2979 | + $pageCountChange = ( $createRedirect ? 1 : 0 ); |
2912 | 2980 | } |
2913 | 2981 | |
2914 | | - if( is_array( $err ) ) { |
| 2982 | + if ( is_array( $err ) ) { |
2915 | 2983 | return $err; |
2916 | 2984 | } |
2917 | 2985 | $redirid = $this->getArticleID(); |
— | — | @@ -2935,7 +3003,7 @@ |
2936 | 3004 | 'cl_sortkey' => $this->getPrefixedText() ), |
2937 | 3005 | __METHOD__ ); |
2938 | 3006 | |
2939 | | - if( $protected ) { |
| 3007 | + if ( $protected ) { |
2940 | 3008 | # Protect the redirect title as the title used to be... |
2941 | 3009 | $dbw->insertSelect( 'page_restrictions', 'page_restrictions', |
2942 | 3010 | array( |
— | — | @@ -2953,8 +3021,8 @@ |
2954 | 3022 | # Update the protection log |
2955 | 3023 | $log = new LogPage( 'protect' ); |
2956 | 3024 | $comment = wfMsgForContent( 'prot_1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() ); |
2957 | | - if( $reason ) $comment .= wfMsgForContent( 'colon-separator' ) . $reason; |
2958 | | - $log->addEntry( 'move_prot', $nt, $comment, array($this->getPrefixedText()) ); // FIXME: $params? |
| 3025 | + if ( $reason ) $comment .= wfMsgForContent( 'colon-separator' ) . $reason; |
| 3026 | + $log->addEntry( 'move_prot', $nt, $comment, array( $this->getPrefixedText() ) ); // FIXME: $params? |
2959 | 3027 | } |
2960 | 3028 | |
2961 | 3029 | # Update watchlists |
— | — | @@ -2963,7 +3031,7 @@ |
2964 | 3032 | $oldtitle = $this->getDBkey(); |
2965 | 3033 | $newtitle = $nt->getDBkey(); |
2966 | 3034 | |
2967 | | - if( $oldnamespace != $newnamespace || $oldtitle != $newtitle ) { |
| 3035 | + if ( $oldnamespace != $newnamespace || $oldtitle != $newtitle ) { |
2968 | 3036 | WatchedItem::duplicateEntries( $this, $nt ); |
2969 | 3037 | } |
2970 | 3038 | |
— | — | @@ -2974,25 +3042,25 @@ |
2975 | 3043 | $u->doUpdate(); |
2976 | 3044 | |
2977 | 3045 | # Update site_stats |
2978 | | - if( $this->isContentPage() && !$nt->isContentPage() ) { |
| 3046 | + if ( $this->isContentPage() && !$nt->isContentPage() ) { |
2979 | 3047 | # No longer a content page |
2980 | 3048 | # Not viewed, edited, removing |
2981 | 3049 | $u = new SiteStatsUpdate( 0, 1, -1, $pageCountChange ); |
2982 | | - } elseif( !$this->isContentPage() && $nt->isContentPage() ) { |
| 3050 | + } elseif ( !$this->isContentPage() && $nt->isContentPage() ) { |
2983 | 3051 | # Now a content page |
2984 | 3052 | # Not viewed, edited, adding |
2985 | | - $u = new SiteStatsUpdate( 0, 1, +1, $pageCountChange ); |
2986 | | - } elseif( $pageCountChange ) { |
| 3053 | + $u = new SiteStatsUpdate( 0, 1, + 1, $pageCountChange ); |
| 3054 | + } elseif ( $pageCountChange ) { |
2987 | 3055 | # Redirect added |
2988 | 3056 | $u = new SiteStatsUpdate( 0, 0, 0, 1 ); |
2989 | 3057 | } else { |
2990 | 3058 | # Nothing special |
2991 | 3059 | $u = false; |
2992 | 3060 | } |
2993 | | - if( $u ) |
| 3061 | + if ( $u ) |
2994 | 3062 | $u->doUpdate(); |
2995 | 3063 | # Update message cache for interface messages |
2996 | | - if( $nt->getNamespace() == NS_MEDIAWIKI ) { |
| 3064 | + if ( $nt->getNamespace() == NS_MEDIAWIKI ) { |
2997 | 3065 | global $wgMessageCache; |
2998 | 3066 | |
2999 | 3067 | # @bug 17860: old article can be deleted, if this the case, |
— | — | @@ -3053,7 +3121,7 @@ |
3054 | 3122 | if ( !$dbw->cascadingDeletes() ) { |
3055 | 3123 | $dbw->delete( 'revision', array( 'rev_page' => $newid ), __METHOD__ ); |
3056 | 3124 | global $wgUseTrackbacks; |
3057 | | - if ($wgUseTrackbacks) |
| 3125 | + if ( $wgUseTrackbacks ) |
3058 | 3126 | $dbw->delete( 'trackbacks', array( 'tb_page' => $newid ), __METHOD__ ); |
3059 | 3127 | $dbw->delete( 'pagelinks', array( 'pl_from' => $newid ), __METHOD__ ); |
3060 | 3128 | $dbw->delete( 'imagelinks', array( 'il_from' => $newid ), __METHOD__ ); |
— | — | @@ -3074,12 +3142,12 @@ |
3075 | 3143 | $nullRevId = $nullRevision->insertOn( $dbw ); |
3076 | 3144 | |
3077 | 3145 | $article = new Article( $this ); |
3078 | | - wfRunHooks( 'NewRevisionFromEditComplete', array($article, $nullRevision, $latest, $wgUser) ); |
| 3146 | + wfRunHooks( 'NewRevisionFromEditComplete', array( $article, $nullRevision, $latest, $wgUser ) ); |
3079 | 3147 | |
3080 | 3148 | # Change the name of the target page: |
3081 | 3149 | $dbw->update( 'page', |
3082 | 3150 | /* SET */ array( |
3083 | | - 'page_touched' => $dbw->timestamp($now), |
| 3151 | + 'page_touched' => $dbw->timestamp( $now ), |
3084 | 3152 | 'page_namespace' => $nt->getNamespace(), |
3085 | 3153 | 'page_title' => $nt->getDBkey(), |
3086 | 3154 | 'page_latest' => $nullRevId, |
— | — | @@ -3090,7 +3158,7 @@ |
3091 | 3159 | $nt->resetArticleID( $oldid ); |
3092 | 3160 | |
3093 | 3161 | # Recreate the redirect, this time in the other direction. |
3094 | | - if( $createRedirect || !$wgUser->isAllowed('suppressredirect') ) { |
| 3162 | + if ( $createRedirect || !$wgUser->isAllowed( 'suppressredirect' ) ) { |
3095 | 3163 | $mwRedir = MagicWord::get( 'redirect' ); |
3096 | 3164 | $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n"; |
3097 | 3165 | $redirectArticle = new Article( $this ); |
— | — | @@ -3102,7 +3170,7 @@ |
3103 | 3171 | $redirectRevision->insertOn( $dbw ); |
3104 | 3172 | $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 ); |
3105 | 3173 | |
3106 | | - wfRunHooks( 'NewRevisionFromEditComplete', array($redirectArticle, $redirectRevision, false, $wgUser) ); |
| 3174 | + wfRunHooks( 'NewRevisionFromEditComplete', array( $redirectArticle, $redirectRevision, false, $wgUser ) ); |
3107 | 3175 | |
3108 | 3176 | # Now, we record the link from the redirect to the new title. |
3109 | 3177 | # It should have no other outgoing links... |
— | — | @@ -3167,7 +3235,7 @@ |
3168 | 3236 | $nullRevId = $nullRevision->insertOn( $dbw ); |
3169 | 3237 | |
3170 | 3238 | $article = new Article( $this ); |
3171 | | - wfRunHooks( 'NewRevisionFromEditComplete', array($article, $nullRevision, $latest, $wgUser) ); |
| 3239 | + wfRunHooks( 'NewRevisionFromEditComplete', array( $article, $nullRevision, $latest, $wgUser ) ); |
3172 | 3240 | |
3173 | 3241 | # Rename page entry |
3174 | 3242 | $dbw->update( 'page', |
— | — | @@ -3182,7 +3250,7 @@ |
3183 | 3251 | ); |
3184 | 3252 | $nt->resetArticleID( $oldid ); |
3185 | 3253 | |
3186 | | - if( $createRedirect || !$wgUser->isAllowed('suppressredirect') ) { |
| 3254 | + if ( $createRedirect || !$wgUser->isAllowed( 'suppressredirect' ) ) { |
3187 | 3255 | # Insert redirect |
3188 | 3256 | $mwRedir = MagicWord::get( 'redirect' ); |
3189 | 3257 | $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n"; |
— | — | @@ -3195,7 +3263,7 @@ |
3196 | 3264 | $redirectRevision->insertOn( $dbw ); |
3197 | 3265 | $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 ); |
3198 | 3266 | |
3199 | | - wfRunHooks( 'NewRevisionFromEditComplete', array($redirectArticle, $redirectRevision, false, $wgUser) ); |
| 3267 | + wfRunHooks( 'NewRevisionFromEditComplete', array( $redirectArticle, $redirectRevision, false, $wgUser ) ); |
3200 | 3268 | |
3201 | 3269 | # Record the just-created redirect's linking to the page |
3202 | 3270 | $dbw->insert( 'pagelinks', |
— | — | @@ -3237,22 +3305,22 @@ |
3238 | 3306 | public function moveSubpages( $nt, $auth = true, $reason = '', $createRedirect = true ) { |
3239 | 3307 | global $wgMaximumMovedPages; |
3240 | 3308 | // Check permissions |
3241 | | - if( !$this->userCan( 'move-subpages' ) ) |
| 3309 | + if ( !$this->userCan( 'move-subpages' ) ) |
3242 | 3310 | return array( 'cant-move-subpages' ); |
3243 | 3311 | // Do the source and target namespaces support subpages? |
3244 | | - if( !MWNamespace::hasSubpages( $this->getNamespace() ) ) |
| 3312 | + if ( !MWNamespace::hasSubpages( $this->getNamespace() ) ) |
3245 | 3313 | return array( 'namespace-nosubpages', |
3246 | 3314 | MWNamespace::getCanonicalName( $this->getNamespace() ) ); |
3247 | | - if( !MWNamespace::hasSubpages( $nt->getNamespace() ) ) |
| 3315 | + if ( !MWNamespace::hasSubpages( $nt->getNamespace() ) ) |
3248 | 3316 | return array( 'namespace-nosubpages', |
3249 | 3317 | MWNamespace::getCanonicalName( $nt->getNamespace() ) ); |
3250 | 3318 | |
3251 | | - $subpages = $this->getSubpages($wgMaximumMovedPages + 1); |
| 3319 | + $subpages = $this->getSubpages( $wgMaximumMovedPages + 1 ); |
3252 | 3320 | $retval = array(); |
3253 | 3321 | $count = 0; |
3254 | | - foreach( $subpages as $oldSubpage ) { |
| 3322 | + foreach ( $subpages as $oldSubpage ) { |
3255 | 3323 | $count++; |
3256 | | - if( $count > $wgMaximumMovedPages ) { |
| 3324 | + if ( $count > $wgMaximumMovedPages ) { |
3257 | 3325 | $retval[$oldSubpage->getPrefixedTitle()] = |
3258 | 3326 | array( 'movepage-max-pages', |
3259 | 3327 | $wgMaximumMovedPages ); |
— | — | @@ -3262,16 +3330,16 @@ |
3263 | 3331 | // We don't know whether this function was called before |
3264 | 3332 | // or after moving the root page, so check both |
3265 | 3333 | // $this and $nt |
3266 | | - if( $oldSubpage->getArticleId() == $this->getArticleId() || |
| 3334 | + if ( $oldSubpage->getArticleId() == $this->getArticleId() || |
3267 | 3335 | $oldSubpage->getArticleID() == $nt->getArticleId() ) |
3268 | 3336 | // When moving a page to a subpage of itself, |
3269 | 3337 | // don't move it twice |
3270 | 3338 | continue; |
3271 | 3339 | $newPageName = preg_replace( |
3272 | | - '#^'.preg_quote( $this->getDBkey(), '#' ).'#', |
| 3340 | + '#^' . preg_quote( $this->getDBkey(), '#' ) . '#', |
3273 | 3341 | StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # bug 21234 |
3274 | 3342 | $oldSubpage->getDBkey() ); |
3275 | | - if( $oldSubpage->isTalkPage() ) { |
| 3343 | + if ( $oldSubpage->isTalkPage() ) { |
3276 | 3344 | $newNs = $nt->getTalkPage()->getNamespace(); |
3277 | 3345 | } else { |
3278 | 3346 | $newNs = $nt->getSubjectPage()->getNamespace(); |
— | — | @@ -3281,7 +3349,7 @@ |
3282 | 3350 | $newSubpage = Title::makeTitleSafe( $newNs, $newPageName ); |
3283 | 3351 | |
3284 | 3352 | $success = $oldSubpage->moveTo( $newSubpage, $auth, $reason, $createRedirect ); |
3285 | | - if( $success === true ) { |
| 3353 | + if ( $success === true ) { |
3286 | 3354 | $retval[$oldSubpage->getPrefixedText()] = $newSubpage->getPrefixedText(); |
3287 | 3355 | } else { |
3288 | 3356 | $retval[$oldSubpage->getPrefixedText()] = $success; |
— | — | @@ -3306,14 +3374,14 @@ |
3307 | 3375 | array( 'FOR UPDATE' ) |
3308 | 3376 | ); |
3309 | 3377 | # Cache some fields we may want |
3310 | | - $this->mArticleID = $row ? intval($row->page_id) : 0; |
| 3378 | + $this->mArticleID = $row ? intval( $row->page_id ) : 0; |
3311 | 3379 | $this->mRedirect = $row ? (bool)$row->page_is_redirect : false; |
3312 | | - $this->mLatestID = $row ? intval($row->page_latest) : false; |
3313 | | - if( !$this->mRedirect ) { |
| 3380 | + $this->mLatestID = $row ? intval( $row->page_latest ) : false; |
| 3381 | + if ( !$this->mRedirect ) { |
3314 | 3382 | return false; |
3315 | 3383 | } |
3316 | 3384 | # Does the article have a history? |
3317 | | - $row = $dbw->selectField( array( 'page', 'revision'), |
| 3385 | + $row = $dbw->selectField( array( 'page', 'revision' ), |
3318 | 3386 | 'rev_id', |
3319 | 3387 | array( 'page_namespace' => $this->getNamespace(), |
3320 | 3388 | 'page_title' => $this->getDBkey(), |
— | — | @@ -3324,7 +3392,7 @@ |
3325 | 3393 | array( 'FOR UPDATE' ) |
3326 | 3394 | ); |
3327 | 3395 | # Return true if there was no history |
3328 | | - return ($row === false); |
| 3396 | + return ( $row === false ); |
3329 | 3397 | } |
3330 | 3398 | |
3331 | 3399 | /** |
— | — | @@ -3337,15 +3405,15 @@ |
3338 | 3406 | public function isValidMoveTarget( $nt ) { |
3339 | 3407 | $dbw = wfGetDB( DB_MASTER ); |
3340 | 3408 | # Is it an existsing file? |
3341 | | - if( $nt->getNamespace() == NS_FILE ) { |
| 3409 | + if ( $nt->getNamespace() == NS_FILE ) { |
3342 | 3410 | $file = wfLocalFile( $nt ); |
3343 | | - if( $file->exists() ) { |
| 3411 | + if ( $file->exists() ) { |
3344 | 3412 | wfDebug( __METHOD__ . ": file exists\n" ); |
3345 | 3413 | return false; |
3346 | 3414 | } |
3347 | 3415 | } |
3348 | 3416 | # Is it a redirect with no history? |
3349 | | - if( !$nt->isSingleRevRedirect() ) { |
| 3417 | + if ( !$nt->isSingleRevRedirect() ) { |
3350 | 3418 | wfDebug( __METHOD__ . ": not a one-rev redirect\n" ); |
3351 | 3419 | return false; |
3352 | 3420 | } |
— | — | @@ -3357,7 +3425,7 @@ |
3358 | 3426 | $m = array(); |
3359 | 3427 | if ( preg_match( "/\\[\\[\\s*([^\\]\\|]*)]]/", $text, $m ) ) { |
3360 | 3428 | $redirTitle = Title::newFromText( $m[1] ); |
3361 | | - if( !is_object( $redirTitle ) || |
| 3429 | + if ( !is_object( $redirTitle ) || |
3362 | 3430 | ( $redirTitle->getPrefixedDBkey() != $this->getPrefixedDBkey() && |
3363 | 3431 | $redirTitle->getPrefixedDBkey() != $nt->getPrefixedDBkey() ) ) { |
3364 | 3432 | wfDebug( __METHOD__ . ": redirect points to other page\n" ); |
— | — | @@ -3396,16 +3464,16 @@ |
3397 | 3465 | |
3398 | 3466 | # NEW SQL |
3399 | 3467 | $sql = "SELECT * FROM $categorylinks" |
3400 | | - ." WHERE cl_from='$titlekey'" |
3401 | | - ." AND cl_from <> '0'" |
3402 | | - ." ORDER BY cl_sortkey"; |
| 3468 | + . " WHERE cl_from='$titlekey'" |
| 3469 | + . " AND cl_from <> '0'" |
| 3470 | + . " ORDER BY cl_sortkey"; |
3403 | 3471 | |
3404 | 3472 | $res = $dbr->query( $sql ); |
3405 | 3473 | |
3406 | | - if( $dbr->numRows( $res ) > 0 ) { |
3407 | | - foreach( $res as $row ) |
3408 | | - //$data[] = Title::newFromText($wgContLang->getNSText ( NS_CATEGORY ).':'.$row->cl_to); |
3409 | | - $data[$wgContLang->getNSText( NS_CATEGORY ).':'.$row->cl_to] = $this->getFullText(); |
| 3474 | + if ( $dbr->numRows( $res ) > 0 ) { |
| 3475 | + foreach ( $res as $row ) |
| 3476 | + // $data[] = Title::newFromText($wgContLang->getNSText ( NS_CATEGORY ).':'.$row->cl_to); |
| 3477 | + $data[$wgContLang->getNSText( NS_CATEGORY ) . ':' . $row->cl_to] = $this->getFullText(); |
3410 | 3478 | $dbr->freeResult( $res ); |
3411 | 3479 | } else { |
3412 | 3480 | $data = array(); |
— | — | @@ -3423,15 +3491,15 @@ |
3424 | 3492 | $stack = array(); |
3425 | 3493 | $parents = $this->getParentCategories(); |
3426 | 3494 | |
3427 | | - if( $parents ) { |
3428 | | - foreach( $parents as $parent => $current ) { |
| 3495 | + if ( $parents ) { |
| 3496 | + foreach ( $parents as $parent => $current ) { |
3429 | 3497 | if ( array_key_exists( $parent, $children ) ) { |
3430 | 3498 | # Circular reference |
3431 | 3499 | $stack[$parent] = array(); |
3432 | 3500 | } else { |
3433 | | - $nt = Title::newFromText($parent); |
| 3501 | + $nt = Title::newFromText( $parent ); |
3434 | 3502 | if ( $nt ) { |
3435 | | - $stack[$parent] = $nt->getParentCategoryTree( $children + array($parent => 1) ); |
| 3503 | + $stack[$parent] = $nt->getParentCategoryTree( $children + array( $parent => 1 ) ); |
3436 | 3504 | } |
3437 | 3505 | } |
3438 | 3506 | } |
— | — | @@ -3449,7 +3517,7 @@ |
3450 | 3518 | * @return \type{\array} Selection array |
3451 | 3519 | */ |
3452 | 3520 | public function pageCond() { |
3453 | | - if( $this->mArticleID > 0 ) { |
| 3521 | + if ( $this->mArticleID > 0 ) { |
3454 | 3522 | // PK avoids secondary lookups in InnoDB, shouldn't hurt other DBs |
3455 | 3523 | return array( 'page_id' => $this->mArticleID ); |
3456 | 3524 | } else { |
— | — | @@ -3464,11 +3532,11 @@ |
3465 | 3533 | * @param $flags \type{\int} GAID_FOR_UPDATE |
3466 | 3534 | * @return \twotypes{\int,\bool} Old revision ID, or FALSE if none exists |
3467 | 3535 | */ |
3468 | | - public function getPreviousRevisionID( $revId, $flags=0 ) { |
3469 | | - $db = ($flags & GAID_FOR_UPDATE) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); |
| 3536 | + public function getPreviousRevisionID( $revId, $flags = 0 ) { |
| 3537 | + $db = ( $flags & GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); |
3470 | 3538 | return $db->selectField( 'revision', 'rev_id', |
3471 | 3539 | array( |
3472 | | - 'rev_page' => $this->getArticleId($flags), |
| 3540 | + 'rev_page' => $this->getArticleId( $flags ), |
3473 | 3541 | 'rev_id < ' . intval( $revId ) |
3474 | 3542 | ), |
3475 | 3543 | __METHOD__, |
— | — | @@ -3483,11 +3551,11 @@ |
3484 | 3552 | * @param $flags \type{\int} GAID_FOR_UPDATE |
3485 | 3553 | * @return \twotypes{\int,\bool} Next revision ID, or FALSE if none exists |
3486 | 3554 | */ |
3487 | | - public function getNextRevisionID( $revId, $flags=0 ) { |
3488 | | - $db = ($flags & GAID_FOR_UPDATE) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); |
| 3555 | + public function getNextRevisionID( $revId, $flags = 0 ) { |
| 3556 | + $db = ( $flags & GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); |
3489 | 3557 | return $db->selectField( 'revision', 'rev_id', |
3490 | 3558 | array( |
3491 | | - 'rev_page' => $this->getArticleId($flags), |
| 3559 | + 'rev_page' => $this->getArticleId( $flags ), |
3492 | 3560 | 'rev_id > ' . intval( $revId ) |
3493 | 3561 | ), |
3494 | 3562 | __METHOD__, |
— | — | @@ -3501,16 +3569,16 @@ |
3502 | 3570 | * @param $flags \type{\int} GAID_FOR_UPDATE |
3503 | 3571 | * @return Revision (or NULL if page doesn't exist) |
3504 | 3572 | */ |
3505 | | - public function getFirstRevision( $flags=0 ) { |
3506 | | - $db = ($flags & GAID_FOR_UPDATE) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); |
3507 | | - $pageId = $this->getArticleId($flags); |
3508 | | - if( !$pageId ) return null; |
| 3573 | + public function getFirstRevision( $flags = 0 ) { |
| 3574 | + $db = ( $flags & GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); |
| 3575 | + $pageId = $this->getArticleId( $flags ); |
| 3576 | + if ( !$pageId ) return null; |
3509 | 3577 | $row = $db->selectRow( 'revision', '*', |
3510 | 3578 | array( 'rev_page' => $pageId ), |
3511 | 3579 | __METHOD__, |
3512 | 3580 | array( 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 1 ) |
3513 | 3581 | ); |
3514 | | - if( !$row ) { |
| 3582 | + if ( !$row ) { |
3515 | 3583 | return null; |
3516 | 3584 | } else { |
3517 | 3585 | return new Revision( $row ); |
— | — | @@ -3534,7 +3602,7 @@ |
3535 | 3603 | */ |
3536 | 3604 | public function getEarliestRevTime() { |
3537 | 3605 | $dbr = wfGetDB( DB_SLAVE ); |
3538 | | - if( $this->exists() ) { |
| 3606 | + if ( $this->exists() ) { |
3539 | 3607 | $min = $dbr->selectField( 'revision', |
3540 | 3608 | 'MIN(rev_timestamp)', |
3541 | 3609 | array( 'rev_page' => $this->getArticleId() ), |
— | — | @@ -3581,7 +3649,7 @@ |
3582 | 3650 | * @return Integer: result of string comparison, or namespace comparison |
3583 | 3651 | */ |
3584 | 3652 | public static function compare( $a, $b ) { |
3585 | | - if( $a->getNamespace() == $b->getNamespace() ) { |
| 3653 | + if ( $a->getNamespace() == $b->getNamespace() ) { |
3586 | 3654 | return strcmp( $a->getText(), $b->getText() ); |
3587 | 3655 | } else { |
3588 | 3656 | return $a->getNamespace() - $b->getNamespace(); |
— | — | @@ -3627,7 +3695,7 @@ |
3628 | 3696 | * @return \type{\bool} |
3629 | 3697 | */ |
3630 | 3698 | public function isAlwaysKnown() { |
3631 | | - if( $this->mInterwiki != '' ) { |
| 3699 | + if ( $this->mInterwiki != '' ) { |
3632 | 3700 | return true; // any interwiki link might be viewable, for all we know |
3633 | 3701 | } |
3634 | 3702 | switch( $this->mNamespace ) { |
— | — | @@ -3690,7 +3758,7 @@ |
3691 | 3759 | * @internal note -- uses hardcoded namespace index instead of constants |
3692 | 3760 | */ |
3693 | 3761 | public function canExist() { |
3694 | | - return $this->mNamespace >=0 && $this->mNamespace != NS_MEDIA; |
| 3762 | + return $this->mNamespace >= 0 && $this->mNamespace != NS_MEDIA; |
3695 | 3763 | } |
3696 | 3764 | |
3697 | 3765 | /** |
— | — | @@ -3715,7 +3783,7 @@ |
3716 | 3784 | * @return \type{\string} Last touched timestamp |
3717 | 3785 | */ |
3718 | 3786 | public function getTouched( $db = null ) { |
3719 | | - $db = isset($db) ? $db : wfGetDB( DB_SLAVE ); |
| 3787 | + $db = isset( $db ) ? $db : wfGetDB( DB_SLAVE ); |
3720 | 3788 | $touched = $db->selectField( 'page', 'page_touched', $this->pageCond(), __METHOD__ ); |
3721 | 3789 | return $touched; |
3722 | 3790 | } |
— | — | @@ -3729,17 +3797,17 @@ |
3730 | 3798 | public function getNotificationTimestamp( $user = null ) { |
3731 | 3799 | global $wgUser, $wgShowUpdatedMarker; |
3732 | 3800 | // Assume current user if none given |
3733 | | - if( !$user ) $user = $wgUser; |
| 3801 | + if ( !$user ) $user = $wgUser; |
3734 | 3802 | // Check cache first |
3735 | 3803 | $uid = $user->getId(); |
3736 | | - if( isset($this->mNotificationTimestamp[$uid]) ) { |
| 3804 | + if ( isset( $this->mNotificationTimestamp[$uid] ) ) { |
3737 | 3805 | return $this->mNotificationTimestamp[$uid]; |
3738 | 3806 | } |
3739 | | - if( !$uid || !$wgShowUpdatedMarker ) { |
| 3807 | + if ( !$uid || !$wgShowUpdatedMarker ) { |
3740 | 3808 | return $this->mNotificationTimestamp[$uid] = false; |
3741 | 3809 | } |
3742 | 3810 | // Don't cache too much! |
3743 | | - if( count($this->mNotificationTimestamp) >= self::CACHE_MAX ) { |
| 3811 | + if ( count( $this->mNotificationTimestamp ) >= self::CACHE_MAX ) { |
3744 | 3812 | $this->mNotificationTimestamp = array(); |
3745 | 3813 | } |
3746 | 3814 | $dbr = wfGetDB( DB_SLAVE ); |
— | — | @@ -3763,7 +3831,7 @@ |
3764 | 3832 | global $wgScriptPath, $wgServer, $wgScriptExtension; |
3765 | 3833 | |
3766 | 3834 | return "$wgServer$wgScriptPath/trackback$wgScriptExtension?article=" |
3767 | | - . htmlspecialchars(urlencode($this->getPrefixedDBkey())); |
| 3835 | + . htmlspecialchars( urlencode( $this->getPrefixedDBkey() ) ); |
3768 | 3836 | } |
3769 | 3837 | |
3770 | 3838 | /** |
— | — | @@ -3772,8 +3840,8 @@ |
3773 | 3841 | * @return \type{\string} Trackback RDF |
3774 | 3842 | */ |
3775 | 3843 | public function trackbackRDF() { |
3776 | | - $url = htmlspecialchars($this->getFullURL()); |
3777 | | - $title = htmlspecialchars($this->getText()); |
| 3844 | + $url = htmlspecialchars( $this->getFullURL() ); |
| 3845 | + $title = htmlspecialchars( $this->getText() ); |
3778 | 3846 | $tburl = $this->trackbackURL(); |
3779 | 3847 | |
3780 | 3848 | // Autodiscovery RDF is placed in comments so HTML validator |
— | — | @@ -3896,7 +3964,7 @@ |
3897 | 3965 | 'rd_title' => $this->getDBkey(), |
3898 | 3966 | 'rd_from = page_id' |
3899 | 3967 | ); |
3900 | | - if ( !is_null($ns) ) $where['page_namespace'] = $ns; |
| 3968 | + if ( !is_null( $ns ) ) $where['page_namespace'] = $ns; |
3901 | 3969 | |
3902 | 3970 | $res = $dbr->select( |
3903 | 3971 | array( 'redirect', 'page' ), |
— | — | @@ -3906,7 +3974,7 @@ |
3907 | 3975 | ); |
3908 | 3976 | |
3909 | 3977 | |
3910 | | - foreach( $res as $row ) { |
| 3978 | + foreach ( $res as $row ) { |
3911 | 3979 | $redirs[] = self::newFromRow( $row ); |
3912 | 3980 | } |
3913 | 3981 | return $redirs; |
— | — | @@ -3921,12 +3989,12 @@ |
3922 | 3990 | global $wgInvalidRedirectTargets; |
3923 | 3991 | |
3924 | 3992 | // invalid redirect targets are stored in a global array, but explicity disallow Userlogout here |
3925 | | - if( $this->isSpecial( 'Userlogout' ) ) { |
| 3993 | + if ( $this->isSpecial( 'Userlogout' ) ) { |
3926 | 3994 | return false; |
3927 | 3995 | } |
3928 | 3996 | |
3929 | | - foreach( $wgInvalidRedirectTargets as $target ) { |
3930 | | - if( $this->isSpecial( $target ) ) { |
| 3997 | + foreach ( $wgInvalidRedirectTargets as $target ) { |
| 3998 | + if ( $this->isSpecial( $target ) ) { |
3931 | 3999 | return false; |
3932 | 4000 | } |
3933 | 4001 | } |
— | — | @@ -3952,7 +4020,7 @@ |
3953 | 4021 | * |
3954 | 4022 | * @return Boolean |
3955 | 4023 | */ |
3956 | | - public function canUseNoindex(){ |
| 4024 | + public function canUseNoindex() { |
3957 | 4025 | global $wgArticleRobotPolicies, $wgContentNamespaces, |
3958 | 4026 | $wgExemptFromUserRobotsControl; |
3959 | 4027 | |
— | — | @@ -3971,7 +4039,7 @@ |
3972 | 4040 | */ |
3973 | 4041 | public function getRestrictionTypes() { |
3974 | 4042 | global $wgRestrictionTypes; |
3975 | | - $types = $this->exists() ? $wgRestrictionTypes : array('create'); |
| 4043 | + $types = $this->exists() ? $wgRestrictionTypes : array( 'create' ); |
3976 | 4044 | |
3977 | 4045 | if ( $this->getNamespace() == NS_FILE ) { |
3978 | 4046 | $types[] = 'upload'; |