r65504 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65503‎ | r65504 | r65505 >
Date:06:22, 24 April 2010
Author:mah
Status:ok (Comments)
Tags:
Comment:
* Refactor super-long title function
* Add tests to achieve almost-complete coverage since I want to make sure my changes don't break thinks.
* Still need to write tests for checkPermissionHooks
* Tests could probably be cleaned up a lot.
Modified paths:
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/maintenance/tests/TitlePermissionTest.php (added) (history)

Diff [purge]

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
1624 + native
Index: trunk/phase3/includes/Title.php
@@ -10,7 +10,7 @@
1111 * and is loaded by UtfNormalUtil.php, which is loaded by UtfNormal.php.
1212 */
1313 if ( !class_exists( 'UtfNormal' ) ) {
14 - require_once( dirname(__FILE__) . '/normal/UtfNormal.php' );
 14+ require_once( dirname( __FILE__ ) . '/normal/UtfNormal.php' );
1515 }
1616
1717 define ( 'GAID_FOR_UPDATE', 1 );
@@ -25,10 +25,10 @@
2626 */
2727 class Title {
2828 /** @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+ // @}
3333
3434 /**
3535 * Title::newFromText maintains a cache to avoid expensive re-normalization of
@@ -43,18 +43,18 @@
4444 * Please use the accessor functions instead.
4545 * @private
4646 */
47 - //@{
 47+ // @{
4848
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
5959 var $mOldRestrictions = false;
6060 var $mCascadeRestriction; ///< Cascade restrictions on this page to included templates and images?
6161 var $mCascadingRestrictions; // Caching the results of getCascadeProtectionSources
@@ -66,21 +66,21 @@
6767 var $mTitleProtection; ///< Cached value of getTitleProtection
6868 # Don't change the following default, NS_MAIN is hardcoded in several
6969 # 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
7171 # 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+ // @}
7878
7979
8080 /**
8181 * Constructor
8282 * @private
8383 */
84 - /* private */ function __construct() {}
 84+ /* private */ function __construct() { }
8585
8686 /**
8787 * Create a new Title from a prefixed DB key
@@ -93,7 +93,7 @@
9494 public static function newFromDBkey( $key ) {
9595 $t = new Title();
9696 $t->mDbkeyform = $key;
97 - if( $t->secureAndSplit() )
 97+ if ( $t->secureAndSplit() )
9898 return $t;
9999 else
100100 return null;
@@ -112,7 +112,7 @@
113113 * @return Title The new object, or null on an error.
114114 */
115115 public static function newFromText( $text, $defaultNamespace = NS_MAIN ) {
116 - if( is_object( $text ) ) {
 116+ if ( is_object( $text ) ) {
117117 throw new MWException( 'Title::newFromText given an object' );
118118 }
119119
@@ -124,7 +124,7 @@
125125 *
126126 * In theory these are value objects and won't get changed...
127127 */
128 - if( $defaultNamespace == NS_MAIN && isset( Title::$titleCache[$text] ) ) {
 128+ if ( $defaultNamespace == NS_MAIN && isset( Title::$titleCache[$text] ) ) {
129129 return Title::$titleCache[$text];
130130 }
131131
@@ -138,12 +138,12 @@
139139 $t->mDefaultNamespace = $defaultNamespace;
140140
141141 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 ) {
145145 # Avoid memory leaks on mass operations...
146146 Title::$titleCache = array();
147 - $cachedcount=0;
 147+ $cachedcount = 0;
148148 }
149149 $cachedcount++;
150150 Title::$titleCache[$text] =& $t;
@@ -182,7 +182,7 @@
183183 }
184184
185185 $t->mDbkeyform = str_replace( ' ', '_', $url );
186 - if( $t->secureAndSplit() ) {
 186+ if ( $t->secureAndSplit() ) {
187187 return $t;
188188 } else {
189189 return null;
@@ -197,9 +197,9 @@
198198 * @return \type{Title} the new object, or NULL on an error
199199 */
200200 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 );
202202 $row = $db->selectRow( 'page', '*', array( 'page_id' => $id ), __METHOD__ );
203 - if( $row !== false ) {
 203+ if ( $row !== false ) {
204204 $title = Title::newFromRow( $row );
205205 } else {
206206 $title = null;
@@ -222,7 +222,7 @@
223223 'page_id IN (' . $dbr->makeList( $ids ) . ')', __METHOD__ );
224224
225225 $titles = array();
226 - foreach( $res as $row ) {
 226+ foreach ( $res as $row ) {
227227 $titles[] = Title::makeTitle( $row->page_namespace, $row->page_title );
228228 }
229229 return $titles;
@@ -237,10 +237,10 @@
238238 public static function newFromRow( $row ) {
239239 $t = self::makeTitle( $row->page_namespace, $row->page_title );
240240
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;
245245
246246 return $t;
247247 }
@@ -282,7 +282,7 @@
283283 public static function makeTitleSafe( $ns, $title, $fragment = '' ) {
284284 $t = new Title();
285285 $t->mDbkeyform = Title::makeName( $ns, $title, $fragment );
286 - if( $t->secureAndSplit() ) {
 286+ if ( $t->secureAndSplit() ) {
287287 return $t;
288288 } else {
289289 return null;
@@ -342,23 +342,23 @@
343343 public static function newFromRedirectArray( $text ) {
344344 global $wgMaxRedirects;
345345 // are redirects disabled?
346 - if( $wgMaxRedirects < 1 )
 346+ if ( $wgMaxRedirects < 1 )
347347 return null;
348348 $title = self::newFromRedirectInternal( $text );
349 - if( is_null( $title ) )
 349+ if ( is_null( $title ) )
350350 return null;
351351 // recursive check to follow double redirects
352352 $recurse = $wgMaxRedirects;
353353 $titles = array( $title );
354 - while( --$recurse > 0 ) {
355 - if( $title->isRedirect() ) {
 354+ while ( --$recurse > 0 ) {
 355+ if ( $title->isRedirect() ) {
356356 $article = new Article( $title, 0 );
357357 $newtitle = $article->getRedirectTarget();
358358 } else {
359359 break;
360360 }
361361 // Redirects to some special pages are not permitted
362 - if( $newtitle instanceOf Title && $newtitle->isValidRedirectTarget() ) {
 362+ if ( $newtitle instanceOf Title && $newtitle->isValidRedirectTarget() ) {
363363 // the new title passes the checks, so make that our current title so that further recursion can be checked
364364 $title = $newtitle;
365365 $titles[] = $newtitle;
@@ -378,16 +378,16 @@
379379 */
380380 protected static function newFromRedirectInternal( $text ) {
381381 $redir = MagicWord::get( 'redirect' );
382 - $text = trim($text);
383 - if( $redir->matchStartAndRemove( $text ) ) {
 382+ $text = trim( $text );
 383+ if ( $redir->matchStartAndRemove( $text ) ) {
384384 // Extract the first link and see if it's usable
385385 // Ensure that it really does come directly after #REDIRECT
386386 // Some older redirects included a colon, so don't freak about that!
387387 $m = array();
388 - if( preg_match( '!^\s*:?\s*\[{2}(.*?)(?:\|.*?)?\]{2}!', $text, $m ) ) {
 388+ if ( preg_match( '!^\s*:?\s*\[{2}(.*?)(?:\|.*?)?\]{2}!', $text, $m ) ) {
389389 // Strip preceding colon used to "escape" categories, etc.
390390 // and URL-decode links
391 - if( strpos( $m[1], '%' ) !== false ) {
 391+ if ( strpos( $m[1], '%' ) !== false ) {
392392 // Match behavior of inline link parsing here;
393393 // don't interpret + as " " most of the time!
394394 // It might be safe to just use rawurldecode instead, though.
@@ -395,7 +395,7 @@
396396 }
397397 $title = Title::newFromText( $m[1] );
398398 // 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() ) {
400400 return null;
401401 }
402402 return $title;
@@ -404,9 +404,9 @@
405405 return null;
406406 }
407407
408 -#----------------------------------------------------------------------------
 408+# ----------------------------------------------------------------------------
409409 # Static functions
410 -#----------------------------------------------------------------------------
 410+# ----------------------------------------------------------------------------
411411
412412 /**
413413 * Get the prefixed DB key associated with an ID
@@ -419,7 +419,7 @@
420420 $dbr = wfGetDB( DB_SLAVE );
421421
422422 $s = $dbr->selectRow( 'page',
423 - array( 'page_namespace','page_title' ),
 423+ array( 'page_namespace', 'page_title' ),
424424 array( 'page_id' => $id ),
425425 __METHOD__ );
426426 if ( $s === false ) { return null; }
@@ -508,7 +508,7 @@
509509 * @return \type{\bool} TRUE if this is transcludable
510510 */
511511 public function isTrans() {
512 - if ($this->mInterwiki == '')
 512+ if ( $this->mInterwiki == '' )
513513 return false;
514514
515515 return Interwiki::fetch( $this->mInterwiki )->isTranscludable();
@@ -516,7 +516,7 @@
517517
518518 /**
519519 * Escape a text fragment, say from a link, for a URL
520 - *
 520+ *
521521 * @param $fragment string containing a URL or link fragment (after the "#")
522522 * @return String: escaped string
523523 */
@@ -528,9 +528,9 @@
529529 return Sanitizer::escapeId( $fragment, 'noninitial' );
530530 }
531531
532 -#----------------------------------------------------------------------------
 532+# ----------------------------------------------------------------------------
533533 # Other stuff
534 -#----------------------------------------------------------------------------
 534+# ----------------------------------------------------------------------------
535535
536536 /** Simple accessors */
537537 /**
@@ -576,7 +576,7 @@
577577 //
578578 // Use the canonical namespaces if possible to try to
579579 // resolve a foreign namespace.
580 - if( MWNamespace::exists( $this->mNamespace ) ) {
 580+ if ( MWNamespace::exists( $this->mNamespace ) ) {
581581 return MWNamespace::getCanonicalName( $this->mNamespace );
582582 }
583583 }
@@ -700,7 +700,7 @@
701701 */
702702 public function getFullText() {
703703 $text = $this->getPrefixedText();
704 - if( $this->mFragment != '' ) {
 704+ if ( $this->mFragment != '' ) {
705705 $text .= '#' . $this->mFragment;
706706 }
707707 return $text;
@@ -712,13 +712,13 @@
713713 * @return \type{\string} Base name
714714 */
715715 public function getBaseText() {
716 - if( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
 716+ if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
717717 return $this->getText();
718718 }
719719
720720 $parts = explode( '/', $this->getText() );
721721 # Don't discard the real title if there's no subpage involved
722 - if( count( $parts ) > 1 )
 722+ if ( count( $parts ) > 1 )
723723 unset( $parts[ count( $parts ) - 1 ] );
724724 return implode( '/', $parts );
725725 }
@@ -729,7 +729,7 @@
730730 * @return \type{\string} Subpage name
731731 */
732732 public function getSubpageText() {
733 - if( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
 733+ if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
734734 return( $this->mTextform );
735735 }
736736 $parts = explode( '/', $this->mTextform );
@@ -771,7 +771,7 @@
772772 public function getFullURL( $query = '', $variant = false ) {
773773 global $wgContLang, $wgServer, $wgRequest;
774774
775 - if( is_array( $query ) ) {
 775+ if ( is_array( $query ) ) {
776776 $query = wfArrayToCGI( $query );
777777 }
778778
@@ -781,7 +781,7 @@
782782
783783 // Ugly quick hack to avoid duplicate prefixes (bug 4571 etc)
784784 // Correct fix would be to move the prepending elsewhere.
785 - if ($wgRequest->getVal('action') != 'render') {
 785+ if ( $wgRequest->getVal( 'action' ) != 'render' ) {
786786 $url = $wgServer . $url;
787787 }
788788 } else {
@@ -819,14 +819,14 @@
820820 global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
821821 global $wgVariantArticlePath, $wgContLang, $wgUser;
822822
823 - if( is_array( $query ) ) {
 823+ if ( is_array( $query ) ) {
824824 $query = wfArrayToCGI( $query );
825825 }
826826
827827 // 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() )
831831 $variant = $pref;
832832 }
833833
@@ -842,8 +842,8 @@
843843 } else {
844844 $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
845845 if ( $query == '' ) {
846 - if( $variant != false && $wgContLang->hasVariants() ) {
847 - if( $wgVariantArticlePath == false ) {
 846+ if ( $variant != false && $wgContLang->hasVariants() ) {
 847+ if ( $wgVariantArticlePath == false ) {
848848 $variantArticlePath = "$wgScript?title=$1&variant=$2"; // default
849849 } else {
850850 $variantArticlePath = $wgVariantArticlePath;
@@ -857,15 +857,15 @@
858858 global $wgActionPaths;
859859 $url = false;
860860 $matches = array();
861 - if( !empty( $wgActionPaths ) &&
 861+ if ( !empty( $wgActionPaths ) &&
862862 preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches ) )
863863 {
864864 $action = urldecode( $matches[2] );
865 - if( isset( $wgActionPaths[$action] ) ) {
 865+ if ( isset( $wgActionPaths[$action] ) ) {
866866 $query = $matches[1];
867 - if( isset( $matches[4] ) ) $query .= $matches[4];
 867+ if ( isset( $matches[4] ) ) $query .= $matches[4];
868868 $url = str_replace( '$1', $dbkey, $wgActionPaths[$action] );
869 - if( $query != '' ) {
 869+ if ( $query != '' ) {
870870 $url = wfAppendQuery( $url, $query );
871871 }
872872 }
@@ -880,7 +880,7 @@
881881
882882 // FIXME: this causes breakage in various places when we
883883 // actually expected a local URL and end up with dupe prefixes.
884 - if ($wgRequest->getVal('action') == 'render') {
 884+ if ( $wgRequest->getVal( 'action' ) == 'render' ) {
885885 $url = $wgServer . $url;
886886 }
887887 }
@@ -907,9 +907,9 @@
908908 */
909909 public function getLinkUrl( $query = array(), $variant = false ) {
910910 wfProfileIn( __METHOD__ );
911 - if( $this->isExternal() ) {
 911+ if ( $this->isExternal() ) {
912912 $ret = $this->getFullURL( $query );
913 - } elseif( $this->getPrefixedText() === '' && $this->getFragment() !== '' ) {
 913+ } elseif ( $this->getPrefixedText() === '' && $this->getFragment() !== '' ) {
914914 $ret = $this->getFragmentForURL();
915915 } else {
916916 $ret = $this->getLocalURL( $query, $variant ) . $this->getFragmentForURL();
@@ -993,11 +993,11 @@
994994 * @return \type{\bool}
995995 */
996996 public function isSemiProtected( $action = 'edit' ) {
997 - if( $this->exists() ) {
 997+ if ( $this->exists() ) {
998998 $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' )
10021002 return false;
10031003 }
10041004 } else {
@@ -1028,11 +1028,11 @@
10291029 return true;
10301030
10311031 # Check regular protection levels
1032 - foreach( $restrictionTypes as $type ){
1033 - if( $action == $type || $action == '' ) {
 1032+ foreach ( $restrictionTypes as $type ) {
 1033+ if ( $action == $type || $action == '' ) {
10341034 $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 != '' ) {
10371037 return true;
10381038 }
10391039 }
@@ -1065,7 +1065,7 @@
10661066 global $wgUser;
10671067
10681068 if ( is_null( $this->mWatched ) ) {
1069 - if ( NS_SPECIAL == $this->mNamespace || !$wgUser->isLoggedIn()) {
 1069+ if ( NS_SPECIAL == $this->mNamespace || !$wgUser->isLoggedIn() ) {
10701070 $this->mWatched = false;
10711071 } else {
10721072 $this->mWatched = $wgUser->isWatched( $this );
@@ -1099,9 +1099,9 @@
11001100 */
11011101 public function isNamespaceProtected() {
11021102 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 ) )
11061106 return true;
11071107 }
11081108 }
@@ -1117,7 +1117,7 @@
11181118 */
11191119 public function userCan( $action, $doExpensiveQueries = true ) {
11201120 global $wgUser;
1121 - return ($this->getUserPermissionsErrorsInternal( $action, $wgUser, $doExpensiveQueries, true ) === array());
 1121+ return ( $this->getUserPermissionsErrorsInternal( $action, $wgUser, $doExpensiveQueries, true ) === array() );
11221122 }
11231123
11241124 /**
@@ -1132,79 +1132,22 @@
11331133 * @return \type{\array} Array of arrays of the arguments to wfMsg to explain permissions problems.
11341134 */
11351135 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
11381139 global $wgUser;
11391140 $wgUser->_unstub( '', 5 );
11401141 $user = $wgUser;
11411142 }
 1143+
11421144 $errors = $this->getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries );
11431145
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 -
12021146 // Remove the errors being ignored.
 1147+ foreach ( $errors as $index => $error ) {
 1148+ $error_key = is_array( $error ) ? $error[0] : $error;
12031149
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] );
12091152 }
12101153 }
12111154
@@ -1212,36 +1155,35 @@
12131156 }
12141157
12151158 /**
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.
12191160 *
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
12251168 */
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() ) {
12361178 // Show user page-specific message only if the user can move other pages
12371179 $errors[] = array( 'cant-move-user-page' );
12381180 }
12391181
12401182 // 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' ) ) {
12421184 $errors[] = array( 'movenotallowedfile' );
12431185 }
12441186
1245 - if( !$user->isAllowed( 'move' ) ) {
 1187+ if ( !$user->isAllowed( 'move' ) ) {
12461188 // User can't move anything
12471189 global $wgGroupPermissions;
12481190 $userCanMove = false;
@@ -1256,40 +1198,33 @@
12571199 // custom message if logged-in users without any special rights can move
12581200 $errors[] = array ( 'movenologintext' );
12591201 } else {
1260 - $errors[] = array ('movenotallowed');
 1202+ $errors[] = array ( 'movenotallowed' );
12611203 }
12621204 }
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' ) ) {
12711207 // 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() ) {
12761211 // Show user page-specific message only if the user can move other pages
12771212 $errors[] = array( 'cant-move-to-user-page' );
12781213 }
1279 - } elseif( !$user->isAllowed( $action ) ) {
 1214+ } elseif ( !$user->isAllowed( $action ) ) {
12801215 $return = null;
12811216
12821217 // We avoid expensive display logic for quickUserCan's and such
12831218 $groups = false;
1284 - if (!$short) {
 1219+ if ( !$short ) {
12851220 $groups = array_map( array( 'User', 'makeGroupLinkWiki' ),
12861221 User::getGroupsWithPermission( $action ) );
12871222 }
12881223
1289 - if( $groups ) {
 1224+ if ( $groups ) {
12901225 global $wgLang;
1291 - $return = array(
 1226+ $return = array(
12921227 'badaccess-groups',
1293 - $wgLang->commaList( $groups ),
 1228+ $wgLang->commaList( $groups ),
12941229 count( $groups )
12951230 );
12961231 } else {
@@ -1298,95 +1233,119 @@
12991234 $errors[] = $return;
13001235 }
13011236
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' );
13061261 }
 1262+ return $errors;
 1263+ }
13071264
 1265+ /**
 1266+ * Check various permission hooks
 1267+ * @see checkQuickPermissions for parameter information
 1268+ */
 1269+ private function checkPermissionHooks( $action, $user, $errors, $doExpensiveQueries, $short ) {
13081270 // Use getUserPermissionsErrors instead
1309 - if( !wfRunHooks( 'userCan', array( &$this, &$user, $action, &$result ) ) ) {
1310 - wfProfileOut( __METHOD__ );
 1271+ if ( !wfRunHooks( 'userCan', array( &$this, &$user, $action, &$result ) ) ) {
13111272 return $result ? array() : array( array( 'badaccess-group0' ) );
13121273 }
13131274 // 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 );
13231277 }
1324 - # Short-circuit point
1325 - if( $short && count($errors) > 0 ) {
1326 - wfProfileOut( __METHOD__ );
1327 - return $errors;
1328 - }
13291278 // 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 );
13391282 }
1340 - # Short-circuit point
1341 - if( $short && count($errors) > 0 ) {
1342 - wfProfileOut( __METHOD__ );
1343 - return $errors;
1344 - }
13451283
 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 ) {
13461292 # Only 'createaccount' and 'execute' can be performed on
13471293 # special pages, which don't actually exist in the DB.
13481294 $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' );
13511297 }
13521298
13531299 # 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 ?
13561302 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 );
13591305 }
13601306
 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 ) {
13611315 # Protect css/js subpages of user pages
13621316 # XXX: this might be better using restrictions
13631317 # XXX: Find a way to work around the php bug that prevents using $this->userCanEditCssSubpage()
13641318 # and $this->userCanEditJsSubpage() from working
13651319 # 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+ }
13761327 }
13771328
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 ) {
13811340 // Backwards compatibility, rewrite sysop -> protect
1382 - if( $right == 'sysop' ) {
 1341+ if ( $right == 'sysop' ) {
13831342 $right = 'protect';
13841343 }
1385 - if( $right != '' && !$user->isAllowed( $right ) ) {
 1344+ if ( $right != '' && !$user->isAllowed( $right ) ) {
13861345 // Users with 'editprotected' permission can edit protected pages
1387 - if( $action=='edit' && $user->isAllowed( 'editprotected' ) ) {
 1346+ if ( $action == 'edit' && $user->isAllowed( 'editprotected' ) ) {
13881347 // Users with 'editprotected' permission cannot edit protected pages
13891348 // with cascading option turned on.
1390 - if( $this->mCascadeRestriction ) {
 1349+ if ( $this->mCascadeRestriction ) {
13911350 $errors[] = array( 'protectedpagetext', $right );
13921351 }
13931352 } else {
@@ -1394,73 +1353,180 @@
13951354 }
13961355 }
13971356 }
1398 - # Short-circuit point
1399 - if( $short && count($errors) > 0 ) {
1400 - wfProfileOut( __METHOD__ );
1401 - return $errors;
1402 - }
14031357
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.
14091372 list( $cascadingSources, $restrictions ) = $this->getCascadeProtectionSources();
14101373 # Cascading protection depends on more than this page...
14111374 # Several cascading protected pages may include this page...
14121375 # Check each cascading level
14131376 # 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 ) {
14161379 $right = ( $right == 'sysop' ) ? 'protect' : $right;
1417 - if( $right != '' && !$user->isAllowed( $right ) ) {
 1380+ if ( $right != '' && !$user->isAllowed( $right ) ) {
14181381 $pages = '';
1419 - foreach( $cascadingSources as $page )
 1382+ foreach ( $cascadingSources as $page )
14201383 $pages .= '* [[:' . $page->getPrefixedText() . "]]\n";
14211384 $errors[] = array( 'cascadeprotected', count( $cascadingSources ), $pages );
14221385 }
14231386 }
14241387 }
14251388 }
1426 - # Short-circuit point
1427 - if( $short && count($errors) > 0 ) {
1428 - wfProfileOut( __METHOD__ );
1429 - return $errors;
1430 - }
14311389
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' );
14351402 }
1436 - }
1437 -
1438 - if( $action == 'create' ) {
 1403+ } elseif ( $action == 'create' ) {
14391404 $title_protection = $this->getTitleProtection();
14401405 if( $title_protection ) {
14411406 if( $title_protection['pt_create_perm'] == 'sysop' ) {
14421407 $title_protection['pt_create_perm'] = 'protect'; // B/C
14431408 }
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'] );
14461411 }
14471412 }
1448 - } elseif( $action == 'move' ) {
 1413+ } elseif ( $action == 'move' ) {
14491414 // Check for immobile pages
1450 - if( !MWNamespace::isMovable( $this->getNamespace() ) ) {
 1415+ if ( !MWNamespace::isMovable( $this->mNamespace ) ) {
14511416 // Specific message for this case
14521417 $errors[] = array( 'immobile-source-namespace', $this->getNsText() );
1453 - } elseif( !$this->isMovable() ) {
 1418+ } elseif ( !$this->isMovable() ) {
14541419 // Less specific message for rarer cases
14551420 $errors[] = array( 'immobile-page' );
14561421 }
1457 - } elseif( $action == 'move-target' ) {
1458 - if( !MWNamespace::isMovable( $this->getNamespace() ) ) {
 1422+ } elseif ( $action == 'move-target' ) {
 1423+ if ( !MWNamespace::isMovable( $this->mNamespace ) ) {
14591424 $errors[] = array( 'immobile-target-namespace', $this->getNsText() );
1460 - } elseif( !$this->isMovable() ) {
 1425+ } elseif ( !$this->isMovable() ) {
14611426 $errors[] = array( 'immobile-target-page' );
14621427 }
14631428 }
 1429+ return $errors;
 1430+ }
14641431
 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+
14651531 wfProfileOut( __METHOD__ );
14661532 return $errors;
14671533 }
@@ -1478,7 +1544,7 @@
14791545 }
14801546
14811547 // Can't protect pages that exist.
1482 - if ($this->exists()) {
 1548+ if ( $this->exists() ) {
14831549 return false;
14841550 }
14851551
@@ -1503,37 +1569,37 @@
15041570 * @return boolean true
15051571 */
15061572 public function updateTitleProtection( $create_perm, $reason, $expiry ) {
1507 - global $wgUser,$wgContLang;
 1573+ global $wgUser, $wgContLang;
15081574
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'] ) {
15111577 // No change
15121578 return true;
15131579 }
15141580
1515 - list ($namespace, $title) = array( $this->getNamespace(), $this->getDBkey() );
 1581+ list ( $namespace, $title ) = array( $this->getNamespace(), $this->getDBkey() );
15161582
15171583 $dbw = wfGetDB( DB_MASTER );
15181584
1519 - $encodedExpiry = Block::encodeExpiry($expiry, $dbw );
 1585+ $encodedExpiry = Block::encodeExpiry( $expiry, $dbw );
15201586
15211587 $expiry_description = '';
15221588 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 ) ) . ')';
15251591 }
15261592 else {
1527 - $expiry_description .= ' (' . wfMsgForContent( 'protect-expiry-indefinite' ).')';
 1593+ $expiry_description .= ' (' . wfMsgForContent( 'protect-expiry-indefinite' ) . ')';
15281594 }
15291595
15301596 # 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' ) ),
15331599 array(
15341600 'pt_namespace' => $namespace,
15351601 'pt_title' => $title,
15361602 'pt_create_perm' => $create_perm,
1537 - 'pt_timestamp' => Block::encodeExpiry(wfTimestampNow(), $dbw),
 1603+ 'pt_timestamp' => Block::encodeExpiry( wfTimestampNow(), $dbw ),
15381604 'pt_expiry' => $encodedExpiry,
15391605 'pt_user' => $wgUser->getId(),
15401606 'pt_reason' => $reason,
@@ -1544,11 +1610,11 @@
15451611 'pt_title' => $title ), __METHOD__ );
15461612 }
15471613 # Update the protection log
1548 - if( $dbw->affectedRows() ) {
 1614+ if ( $dbw->affectedRows() ) {
15491615 $log = new LogPage( 'protect' );
15501616
1551 - if( $create_perm ) {
1552 - $params = array("[create=$create_perm] $expiry_description",'');
 1617+ if ( $create_perm ) {
 1618+ $params = array( "[create=$create_perm] $expiry_description", '' );
15531619 $log->addEntry( ( isset( $this->mRestrictions['create'] ) && $this->mRestrictions['create'] ) ? 'modify' : 'protect', $this, trim( $reason ), $params );
15541620 } else {
15551621 $log->addEntry( 'unprotect', $this, $reason );
@@ -1591,21 +1657,21 @@
15921658 static $useShortcut = null;
15931659
15941660 # 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 ) ) {
15961662 global $wgRevokePermissions;
15971663 $useShortcut = true;
1598 - if( empty( $wgGroupPermissions['*']['read'] ) ) {
 1664+ if ( empty( $wgGroupPermissions['*']['read'] ) ) {
15991665 # Not a public wiki, so no shortcut
16001666 $useShortcut = false;
1601 - } elseif( !empty( $wgRevokePermissions ) ) {
 1667+ } elseif ( !empty( $wgRevokePermissions ) ) {
16021668 /*
16031669 * Iterate through each group with permissions being revoked (key not included since we don't care
16041670 * what the group name is), then check if the read permission is being revoked. If it is, then
16051671 * we don't use the shortcut below since the user might not be able to read, even though anon
16061672 * reading is allowed.
16071673 */
1608 - foreach( $wgRevokePermissions as $perms ) {
1609 - if( !empty( $perms['read'] ) ) {
 1674+ foreach ( $wgRevokePermissions as $perms ) {
 1675+ if ( !empty( $perms['read'] ) ) {
16101676 # We might be removing the read right from the user, so no shortcut
16111677 $useShortcut = false;
16121678 break;
@@ -1624,7 +1690,7 @@
16251691 if ( $useShortcut )
16261692 return true;
16271693
1628 - if( $wgUser->isAllowed( 'read' ) ) {
 1694+ if ( $wgUser->isAllowed( 'read' ) ) {
16291695 return true;
16301696 } else {
16311697 global $wgWhitelistRead;
@@ -1633,14 +1699,14 @@
16341700 * Always grant access to the login page.
16351701 * Even anons need to be able to log in.
16361702 */
1637 - if( $this->isSpecial( 'Userlogin' ) || $this->isSpecial( 'Resetpass' ) ) {
 1703+ if ( $this->isSpecial( 'Userlogin' ) || $this->isSpecial( 'Resetpass' ) ) {
16381704 return true;
16391705 }
16401706
16411707 /**
16421708 * Bail out if there isn't whitelist
16431709 */
1644 - if( !is_array($wgWhitelistRead) ) {
 1710+ if ( !is_array( $wgWhitelistRead ) ) {
16451711 return false;
16461712 }
16471713
@@ -1650,15 +1716,15 @@
16511717 $name = $this->getPrefixedText();
16521718 $dbName = $this->getPrefixedDBKey();
16531719 // 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 ) )
16551721 return true;
16561722
16571723 /**
16581724 * Old settings might have the title prefixed with
16591725 * a colon for main-namespace pages
16601726 */
1661 - if( $this->getNamespace() == NS_MAIN ) {
1662 - if( in_array( ':' . $name, $wgWhitelistRead ) )
 1727+ if ( $this->getNamespace() == NS_MAIN ) {
 1728+ if ( in_array( ':' . $name, $wgWhitelistRead ) )
16631729 return true;
16641730 }
16651731
@@ -1666,16 +1732,16 @@
16671733 * If it's a special page, ditch the subpage bit
16681734 * and check again
16691735 */
1670 - if( $this->getNamespace() == NS_SPECIAL ) {
 1736+ if ( $this->getNamespace() == NS_SPECIAL ) {
16711737 $name = $this->getDBkey();
1672 - list( $name, /* $subpage */) = SpecialPage::resolveAliasWithSubpage( $name );
 1738+ list( $name, /* $subpage */ ) = SpecialPage::resolveAliasWithSubpage( $name );
16731739 if ( $name === false ) {
16741740 # Invalid special page, but we show standard login required message
16751741 return false;
16761742 }
16771743
16781744 $pure = SpecialPage::getTitleFor( $name )->getPrefixedText();
1679 - if( in_array( $pure, $wgWhitelistRead, true ) )
 1745+ if ( in_array( $pure, $wgWhitelistRead, true ) )
16801746 return true;
16811747 }
16821748
@@ -1709,7 +1775,7 @@
17101776 * @return \type{\bool}
17111777 */
17121778 public function hasSubpages() {
1713 - if( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
 1779+ if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
17141780 # Duh
17151781 return false;
17161782 }
@@ -1718,12 +1784,12 @@
17191785 # alone to cache the result. There's no point in having it hanging
17201786 # around uninitialized in every Title object; therefore we only add it
17211787 # if needed and don't declare it statically.
1722 - if( isset( $this->mHasSubpages ) ) {
 1788+ if ( isset( $this->mHasSubpages ) ) {
17231789 return $this->mHasSubpages;
17241790 }
17251791
17261792 $subpages = $this->getSubpages( 1 );
1727 - if( $subpages instanceof TitleArray )
 1793+ if ( $subpages instanceof TitleArray )
17281794 return $this->mHasSubpages = (bool)$subpages->count();
17291795 return $this->mHasSubpages = false;
17301796 }
@@ -1736,14 +1802,14 @@
17371803 * doesn't allow subpages
17381804 */
17391805 public function getSubpages( $limit = -1 ) {
1740 - if( !MWNamespace::hasSubpages( $this->getNamespace() ) )
 1806+ if ( !MWNamespace::hasSubpages( $this->getNamespace() ) )
17411807 return array();
17421808
17431809 $dbr = wfGetDB( DB_SLAVE );
17441810 $conds['page_namespace'] = $this->getNamespace();
17451811 $conds[] = 'page_title ' . $dbr->buildLike( $this->getDBkey() . '/', $dbr->anyString() );
17461812 $options = array();
1747 - if( $limit > -1 )
 1813+ if ( $limit > -1 )
17481814 $options['LIMIT'] = $limit;
17491815 return $this->mSubpages = TitleArray::newFromResult(
17501816 $dbr->select( 'page',
@@ -1771,7 +1837,7 @@
17721838 * @return \type{\bool}
17731839 */
17741840 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 ) );
17761842 }
17771843
17781844 /**
@@ -1808,7 +1874,7 @@
18091875 * @return \type{\bool}
18101876 */
18111877 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 ) );
18131879 }
18141880
18151881 /**
@@ -1817,7 +1883,7 @@
18181884 * @return \type{\bool}
18191885 */
18201886 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 ) );
18221888 }
18231889
18241890 /**
@@ -1829,8 +1895,8 @@
18301896 */
18311897 public function userCanEditCssSubpage() {
18321898 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 ) );
18351901 }
18361902 /**
18371903 * Protect js subpages of user pages: can $wgUser edit
@@ -1841,8 +1907,8 @@
18421908 */
18431909 public function userCanEditJsSubpage() {
18441910 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 ) );
18471913 }
18481914
18491915 /**
@@ -1858,20 +1924,20 @@
18591925 /**
18601926 * Cascading protection: Get the source of any cascading restrictions on this page.
18611927 *
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
18631929 * that the restrictions have come from.
18641930 * @return \type{\arrayof{mixed title array, restriction array}} Array of the Title
18651931 * 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.
18671933 * The restriction array is an array of each type, each of which contains a
18681934 * array of unique groups.
18691935 */
1870 - public function getCascadeProtectionSources( $get_pages = true ) {
 1936+ public function getCascadeProtectionSources( $getPages = true ) {
18711937 $pagerestrictions = array();
18721938
1873 - if ( isset( $this->mCascadeSources ) && $get_pages ) {
 1939+ if ( isset( $this->mCascadeSources ) && $getPages ) {
18741940 return array( $this->mCascadeSources, $this->mCascadingRestrictions );
1875 - } else if ( isset( $this->mHasCascadingRestrictions ) && !$get_pages ) {
 1941+ } else if ( isset( $this->mHasCascadingRestrictions ) && !$getPages ) {
18761942 return array( $this->mHasCascadingRestrictions, $pagerestrictions );
18771943 }
18781944
@@ -1880,13 +1946,13 @@
18811947 $dbr = wfGetDB( DB_SLAVE );
18821948
18831949 if ( $this->getNamespace() == NS_FILE ) {
1884 - $tables = array ('imagelinks', 'page_restrictions');
 1950+ $tables = array ( 'imagelinks', 'page_restrictions' );
18851951 $where_clauses = array(
18861952 'il_to' => $this->getDBkey(),
18871953 'il_from=pr_page',
18881954 'pr_cascade' => 1 );
18891955 } else {
1890 - $tables = array ('templatelinks', 'page_restrictions');
 1956+ $tables = array ( 'templatelinks', 'page_restrictions' );
18911957 $where_clauses = array(
18921958 'tl_namespace' => $this->getNamespace(),
18931959 'tl_title' => $this->getDBkey(),
@@ -1894,8 +1960,9 @@
18951961 'pr_cascade' => 1 );
18961962 }
18971963
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' );
19001967 $where_clauses[] = 'page_id=pr_page';
19011968 $tables[] = 'page';
19021969 } else {
@@ -1904,18 +1971,18 @@
19051972
19061973 $res = $dbr->select( $tables, $cols, $where_clauses, __METHOD__ );
19071974
1908 - $sources = $get_pages ? array() : false;
 1975+ $sources = $getPages ? array() : false;
19091976 $now = wfTimestampNow();
19101977 $purgeExpired = false;
19111978
1912 - foreach( $res as $row ) {
 1979+ foreach ( $res as $row ) {
19131980 $expiry = Block::decodeExpiry( $row->pr_expiry );
1914 - if( $expiry > $now ) {
1915 - if ($get_pages) {
 1981+ if ( $expiry > $now ) {
 1982+ if ( $getPages ) {
19161983 $page_id = $row->pr_page;
19171984 $page_ns = $row->page_namespace;
19181985 $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 );
19201987 # Add groups needed for each restriction type if its not already there
19211988 # Make sure this restriction type still exists
19221989
@@ -1923,9 +1990,9 @@
19241991 $pagerestrictions[$row->pr_type] = array();
19251992 }
19261993
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;
19301997 }
19311998 } else {
19321999 $sources = true;
@@ -1935,18 +2002,19 @@
19362003 $purgeExpired = true;
19372004 }
19382005 }
1939 - if( $purgeExpired ) {
 2006+ if ( $purgeExpired ) {
19402007 Title::purgeExpiredRestrictions();
19412008 }
19422009
19432010 wfProfileOut( __METHOD__ );
19442011
1945 - if ( $get_pages ) {
 2012+ if ( $getPages ) {
19462013 $this->mCascadeSources = $sources;
19472014 $this->mCascadingRestrictions = $pagerestrictions;
19482015 } else {
19492016 $this->mHasCascadingRestrictions = $sources;
19502017 }
 2018+
19512019 return array( $sources, $pagerestrictions );
19522020 }
19532021
@@ -1956,7 +2024,7 @@
19572025 * @return Boolean
19582026 */
19592027 function areRestrictionsCascading() {
1960 - if (!$this->mRestrictionsLoaded) {
 2028+ if ( !$this->mRestrictionsLoaded ) {
19612029 $this->loadRestrictions();
19622030 }
19632031
@@ -1974,7 +2042,7 @@
19752043 $rows = array();
19762044 $dbr = wfGetDB( DB_SLAVE );
19772045
1978 - while( $row = $dbr->fetchObject( $res ) ) {
 2046+ while ( $row = $dbr->fetchObject( $res ) ) {
19792047 $rows[] = $row;
19802048 }
19812049
@@ -1994,9 +2062,9 @@
19952063
19962064 $restrictionTypes = $this->getRestrictionTypes();
19972065
1998 - foreach( $restrictionTypes as $type ){
 2066+ foreach ( $restrictionTypes as $type ) {
19992067 $this->mRestrictions[$type] = array();
2000 - $this->mRestrictionsExpiry[$type] = Block::decodeExpiry('');
 2068+ $this->mRestrictionsExpiry[$type] = Block::decodeExpiry( '' );
20012069 }
20022070
20032071 $this->mCascadeRestriction = false;
@@ -2008,11 +2076,11 @@
20092077 array( 'page_id' => $this->getArticleId() ), __METHOD__ );
20102078 }
20112079
2012 - if ($oldFashionedRestrictions != '') {
 2080+ if ( $oldFashionedRestrictions != '' ) {
20132081
2014 - foreach( explode( ':', trim( $oldFashionedRestrictions ) ) as $restrict ) {
 2082+ foreach ( explode( ':', trim( $oldFashionedRestrictions ) ) as $restrict ) {
20152083 $temp = explode( '=', trim( $restrict ) );
2016 - if(count($temp) == 1) {
 2084+ if ( count( $temp ) == 1 ) {
20172085 // old old format should be treated as edit/move restriction
20182086 $this->mRestrictions['edit'] = explode( ',', trim( $temp[0] ) );
20192087 $this->mRestrictions['move'] = explode( ',', trim( $temp[0] ) );
@@ -2025,17 +2093,17 @@
20262094
20272095 }
20282096
2029 - if( count($rows) ) {
 2097+ if ( count( $rows ) ) {
20302098 # Current system - load second to make them override.
20312099 $now = wfTimestampNow();
20322100 $purgeExpired = false;
20332101
2034 - foreach( $rows as $row ) {
 2102+ foreach ( $rows as $row ) {
20352103 # Cycle through all the restrictions.
20362104
20372105 // Don't take care of restrictions types that aren't allowed
20382106
2039 - if( !in_array( $row->pr_type, $restrictionTypes ) )
 2107+ if ( !in_array( $row->pr_type, $restrictionTypes ) )
20402108 continue;
20412109
20422110 // This code should be refactored, now that it's being used more generally,
@@ -2054,7 +2122,7 @@
20552123 }
20562124 }
20572125
2058 - if( $purgeExpired ) {
 2126+ if ( $purgeExpired ) {
20592127 Title::purgeExpiredRestrictions();
20602128 }
20612129 }
@@ -2069,8 +2137,8 @@
20702138 * restrictions from page table (pre 1.10)
20712139 */
20722140 public function loadRestrictions( $oldFashionedRestrictions = null ) {
2073 - if( !$this->mRestrictionsLoaded ) {
2074 - if ($this->exists()) {
 2141+ if ( !$this->mRestrictionsLoaded ) {
 2142+ if ( $this->exists() ) {
20752143 $dbr = wfGetDB( DB_SLAVE );
20762144
20772145 $res = $dbr->select( 'page_restrictions', '*',
@@ -2080,19 +2148,19 @@
20812149 } else {
20822150 $title_protection = $this->getTitleProtection();
20832151
2084 - if ($title_protection) {
 2152+ if ( $title_protection ) {
20852153 $now = wfTimestampNow();
2086 - $expiry = Block::decodeExpiry($title_protection['pt_expiry']);
 2154+ $expiry = Block::decodeExpiry( $title_protection['pt_expiry'] );
20872155
2088 - if (!$expiry || $expiry > $now) {
 2156+ if ( !$expiry || $expiry > $now ) {
20892157 // Apply the restrictions
20902158 $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'] ) );
20922160 } else { // Get rid of the old restrictions
20932161 Title::purgeExpiredRestrictions();
20942162 }
20952163 } else {
2096 - $this->mRestrictionsExpiry['create'] = Block::decodeExpiry('');
 2164+ $this->mRestrictionsExpiry['create'] = Block::decodeExpiry( '' );
20972165 }
20982166 $this->mRestrictionsLoaded = true;
20992167 }
@@ -2120,7 +2188,7 @@
21212189 * @return \type{\arrayof{\string}} the array of groups allowed to edit this article
21222190 */
21232191 public function getRestrictions( $action ) {
2124 - if( !$this->mRestrictionsLoaded ) {
 2192+ if ( !$this->mRestrictionsLoaded ) {
21252193 $this->loadRestrictions();
21262194 }
21272195 return isset( $this->mRestrictions[$action] )
@@ -2135,7 +2203,7 @@
21362204 * or not protected at all, or false if the action is not recognised.
21372205 */
21382206 public function getRestrictionExpiry( $action ) {
2139 - if( !$this->mRestrictionsLoaded ) {
 2207+ if ( !$this->mRestrictionsLoaded ) {
21402208 $this->loadRestrictions();
21412209 }
21422210 return isset( $this->mRestrictionsExpiry[$action] ) ? $this->mRestrictionsExpiry[$action] : false;
@@ -2147,7 +2215,7 @@
21482216 * @return \type{\int} the number of archived revisions
21492217 */
21502218 public function isDeleted() {
2151 - if( $this->getNamespace() < 0 ) {
 2219+ if ( $this->getNamespace() < 0 ) {
21522220 $n = 0;
21532221 } else {
21542222 $dbr = wfGetDB( DB_SLAVE );
@@ -2155,7 +2223,7 @@
21562224 array( 'ar_namespace' => $this->getNamespace(), 'ar_title' => $this->getDBkey() ),
21572225 __METHOD__
21582226 );
2159 - if( $this->getNamespace() == NS_FILE ) {
 2227+ if ( $this->getNamespace() == NS_FILE ) {
21602228 $n += $dbr->selectField( 'filearchive', 'COUNT(*)',
21612229 array( 'fa_name' => $this->getDBkey() ),
21622230 __METHOD__
@@ -2171,7 +2239,7 @@
21722240 * @return Boolean
21732241 */
21742242 public function isDeletedQuick() {
2175 - if( $this->getNamespace() < 0 ) {
 2243+ if ( $this->getNamespace() < 0 ) {
21762244 return false;
21772245 }
21782246 $dbr = wfGetDB( DB_SLAVE );
@@ -2179,7 +2247,7 @@
21802248 array( 'ar_namespace' => $this->getNamespace(), 'ar_title' => $this->getDBkey() ),
21812249 __METHOD__
21822250 );
2183 - if( !$deleted && $this->getNamespace() == NS_FILE ) {
 2251+ if ( !$deleted && $this->getNamespace() == NS_FILE ) {
21842252 $deleted = (bool)$dbr->selectField( 'filearchive', '1',
21852253 array( 'fa_name' => $this->getDBkey() ),
21862254 __METHOD__
@@ -2197,17 +2265,17 @@
21982266 * @return \type{\int} the ID
21992267 */
22002268 public function getArticleID( $flags = 0 ) {
2201 - if( $this->getNamespace() < 0 ) {
 2269+ if ( $this->getNamespace() < 0 ) {
22022270 return $this->mArticleID = 0;
22032271 }
22042272 $linkCache = LinkCache::singleton();
2205 - if( $flags & GAID_FOR_UPDATE ) {
 2273+ if ( $flags & GAID_FOR_UPDATE ) {
22062274 $oldUpdate = $linkCache->forUpdate( true );
22072275 $linkCache->clearLink( $this );
22082276 $this->mArticleID = $linkCache->addLinkObj( $this );
22092277 $linkCache->forUpdate( $oldUpdate );
22102278 } else {
2211 - if( -1 == $this->mArticleID ) {
 2279+ if ( -1 == $this->mArticleID ) {
22122280 $this->mArticleID = $linkCache->addLinkObj( $this );
22132281 }
22142282 }
@@ -2222,10 +2290,10 @@
22232291 * @return \type{\bool}
22242292 */
22252293 public function isRedirect( $flags = 0 ) {
2226 - if( !is_null($this->mRedirect) )
 2294+ if ( !is_null( $this->mRedirect ) )
22272295 return $this->mRedirect;
22282296 # Calling getArticleID() loads the field from cache as needed
2229 - if( !$this->getArticleID($flags) ) {
 2297+ if ( !$this->getArticleID( $flags ) ) {
22302298 return $this->mRedirect = false;
22312299 }
22322300 $linkCache = LinkCache::singleton();
@@ -2242,10 +2310,10 @@
22432311 * @return \type{\bool}
22442312 */
22452313 public function getLength( $flags = 0 ) {
2246 - if( $this->mLength != -1 )
 2314+ if ( $this->mLength != -1 )
22472315 return $this->mLength;
22482316 # Calling getArticleID() loads the field from cache as needed
2249 - if( !$this->getArticleID($flags) ) {
 2317+ if ( !$this->getArticleID( $flags ) ) {
22502318 return $this->mLength = 0;
22512319 }
22522320 $linkCache = LinkCache::singleton();
@@ -2261,10 +2329,10 @@
22622330 * @return \type{\int} or false if the page doesn't exist
22632331 */
22642332 public function getLatestRevID( $flags = 0 ) {
2265 - if( $this->mLatestID !== false )
 2333+ if ( $this->mLatestID !== false )
22662334 return $this->mLatestID;
22672335
2268 - $db = ($flags & GAID_FOR_UPDATE) ? wfGetDB(DB_MASTER) : wfGetDB(DB_SLAVE);
 2336+ $db = ( $flags & GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
22692337 $this->mLatestID = (int)$db->selectField(
22702338 'page', 'page_latest', $this->pageCond(), __METHOD__ );
22712339 return $this->mLatestID;
@@ -2302,7 +2370,7 @@
23032371 * @return \type{\bool} true if the update succeded
23042372 */
23052373 public function invalidateCache() {
2306 - if( wfReadOnly() ) {
 2374+ if ( wfReadOnly() ) {
23072375 return;
23082376 }
23092377 $dbw = wfGetDB( DB_MASTER );
@@ -2343,7 +2411,7 @@
23442412 */
23452413 static function getTitleInvalidRegex() {
23462414 static $rxTc = false;
2347 - if( !$rxTc ) {
 2415+ if ( !$rxTc ) {
23482416 # Matching titles will be held as illegal.
23492417 $rxTc = '/' .
23502418 # Any character not allowed is forbidden...
@@ -2416,7 +2484,7 @@
24172485 return false;
24182486 }
24192487
2420 - if( false !== strpos( $dbkey, UTF8_REPLACEMENT ) ) {
 2488+ if ( false !== strpos( $dbkey, UTF8_REPLACEMENT ) ) {
24212489 # Contained illegal UTF-8 sequences or forbidden Unicode chars.
24222490 return false;
24232491 }
@@ -2425,7 +2493,7 @@
24262494
24272495 # Initial colon indicates main namespace rather than specified default
24282496 # but should not create invalid {ns,title} pairs such as {0,Project:Foo}
2429 - if ( ':' == $dbkey{0} ) {
 2497+ if ( ':' == $dbkey { 0 } ) {
24302498 $this->mNamespace = NS_MAIN;
24312499 $dbkey = substr( $dbkey, 1 ); # remove the colon but continue processing
24322500 $dbkey = trim( $dbkey, '_' ); # remove any subsequent whitespace
@@ -2443,14 +2511,14 @@
24442512 $dbkey = $m[2];
24452513 $this->mNamespace = $ns;
24462514 # 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] ) )
24492517 return false; # Disallow Talk:File:x type titles...
2450 - else if( Interwiki::isValidInterwiki( $x[1] ) )
 2518+ else if ( Interwiki::isValidInterwiki( $x[1] ) )
24512519 return false; # Disallow Talk:Interwiki:x type titles...
24522520 }
2453 - } elseif( Interwiki::isValidInterwiki( $p ) ) {
2454 - if( !$firstPass ) {
 2521+ } elseif ( Interwiki::isValidInterwiki( $p ) ) {
 2522+ if ( !$firstPass ) {
24552523 # Can't make a local interwiki link to an interwiki link.
24562524 # That's just crazy!
24572525 return false;
@@ -2462,7 +2530,7 @@
24632531
24642532 # Redundant interwiki prefix to the local wiki
24652533 if ( 0 == strcasecmp( $this->mInterwiki, $wgLocalInterwiki ) ) {
2466 - if( $dbkey == '' ) {
 2534+ if ( $dbkey == '' ) {
24672535 # Can't have an empty self-link
24682536 return false;
24692537 }
@@ -2483,7 +2551,7 @@
24842552 # then let the colon expression be part of the title.
24852553 }
24862554 break;
2487 - } while( true );
 2555+ } while ( true );
24882556
24892557 # We already know that some pages won't be in the database!
24902558 #
@@ -2501,7 +2569,7 @@
25022570
25032571 # Reject illegal characters.
25042572 #
2505 - if( preg_match( $rxTc, $dbkey ) ) {
 2573+ if ( preg_match( $rxTc, $dbkey ) ) {
25062574 return false;
25072575 }
25082576
@@ -2525,7 +2593,7 @@
25262594 /**
25272595 * Magic tilde sequences? Nu-uh!
25282596 */
2529 - if( strpos( $dbkey, '~~~' ) !== false ) {
 2597+ if ( strpos( $dbkey, '~~~' ) !== false ) {
25302598 return false;
25312599 }
25322600
@@ -2551,7 +2619,7 @@
25522620 * site might be case-sensitive.
25532621 */
25542622 $this->mUserCaseDBKey = $dbkey;
2555 - if( $this->mInterwiki == '') {
 2623+ if ( $this->mInterwiki == '' ) {
25562624 $dbkey = self::capitalize( $dbkey, $this->mNamespace );
25572625 }
25582626
@@ -2560,7 +2628,7 @@
25612629 * "empty" local links can only be self-links
25622630 * with a fragment identifier.
25632631 */
2564 - if( $dbkey == '' &&
 2632+ if ( $dbkey == '' &&
25652633 $this->mInterwiki == '' &&
25662634 $this->mNamespace != NS_MAIN ) {
25672635 return false;
@@ -2571,10 +2639,10 @@
25722640 // there are numerous ways to present the same IP. Having sp:contribs scan
25732641 // them all is silly and having some show the edits and others not is
25742642 // 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 ) ?
25762644 IP::sanitizeIP( $dbkey ) : $dbkey;
25772645 // Any remaining initial :s are illegal.
2578 - if ( $dbkey !== '' && ':' == $dbkey{0} ) {
 2646+ if ( $dbkey !== '' && ':' == $dbkey { 0 } ) {
25792647 return false;
25802648 }
25812649
@@ -2619,7 +2687,7 @@
26202688 public function getSubjectPage() {
26212689 // Is this the same title?
26222690 $subjectNS = MWNamespace::getSubject( $this->getNamespace() );
2623 - if( $this->getNamespace() == $subjectNS ) {
 2691+ if ( $this->getNamespace() == $subjectNS ) {
26242692 return $this;
26252693 }
26262694 return Title::makeTitle( $subjectNS, $this->getDBkey() );
@@ -2657,7 +2725,7 @@
26582726
26592727 $retVal = array();
26602728 if ( $db->numRows( $res ) ) {
2661 - foreach( $res as $row ) {
 2729+ foreach ( $res as $row ) {
26622730 if ( $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title ) ) {
26632731 $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect );
26642732 $retVal[] = $titleObj;
@@ -2712,7 +2780,7 @@
27132781 );
27142782
27152783 $retVal = array();
2716 - foreach( $res as $row ) {
 2784+ foreach ( $res as $row ) {
27172785 $retVal[] = Title::makeTitle( $row->pl_namespace, $row->pl_title );
27182786 }
27192787 return $retVal;
@@ -2734,11 +2802,11 @@
27352803 );
27362804
27372805 // purge variant urls as well
2738 - if($wgContLang->hasVariants()){
 2806+ if ( $wgContLang->hasVariants() ) {
27392807 $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 );
27432811 }
27442812 }
27452813
@@ -2781,52 +2849,52 @@
27822850 global $wgUser;
27832851
27842852 $errors = array();
2785 - if( !$nt ) {
 2853+ if ( !$nt ) {
27862854 // Normally we'd add this to $errors, but we'll get
27872855 // lots of syntax errors if $nt is not an object
2788 - return array(array('badtitletext'));
 2856+ return array( array( 'badtitletext' ) );
27892857 }
2790 - if( $this->equals( $nt ) ) {
2791 - $errors[] = array('selfmove');
 2858+ if ( $this->equals( $nt ) ) {
 2859+ $errors[] = array( 'selfmove' );
27922860 }
2793 - if( !$this->isMovable() ) {
 2861+ if ( !$this->isMovable() ) {
27942862 $errors[] = array( 'immobile-source-namespace', $this->getNsText() );
27952863 }
27962864 if ( $nt->getInterwiki() != '' ) {
27972865 $errors[] = array( 'immobile-target-namespace-iw' );
27982866 }
27992867 if ( !$nt->isMovable() ) {
2800 - $errors[] = array('immobile-target-namespace', $nt->getNsText() );
 2868+ $errors[] = array( 'immobile-target-namespace', $nt->getNsText() );
28012869 }
28022870
28032871 $oldid = $this->getArticleID();
28042872 $newid = $nt->getArticleID();
28052873
28062874 if ( strlen( $nt->getDBkey() ) < 1 ) {
2807 - $errors[] = array('articleexists');
 2875+ $errors[] = array( 'articleexists' );
28082876 }
28092877 if ( ( $this->getDBkey() == '' ) ||
28102878 ( !$oldid ) ||
28112879 ( $nt->getDBkey() == '' ) ) {
2812 - $errors[] = array('badarticleerror');
 2880+ $errors[] = array( 'badarticleerror' );
28132881 }
28142882
28152883 // Image-specific checks
2816 - if( $this->getNamespace() == NS_FILE ) {
 2884+ if ( $this->getNamespace() == NS_FILE ) {
28172885 $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' );
28212889 }
2822 - if( $nt->getText() != wfStripIllegalFilenameChars( $nt->getText() ) ) {
2823 - $errors[] = array('imageinvalidfilename');
 2890+ if ( $nt->getText() != wfStripIllegalFilenameChars( $nt->getText() ) ) {
 2891+ $errors[] = array( 'imageinvalidfilename' );
28242892 }
2825 - if( !File::checkExtensionCompatibility( $file, $nt->getDBkey() ) ) {
2826 - $errors[] = array('imagetypemismatch');
 2893+ if ( !File::checkExtensionCompatibility( $file, $nt->getDBkey() ) ) {
 2894+ $errors[] = array( 'imagetypemismatch' );
28272895 }
28282896 }
28292897 $destfile = wfLocalFile( $nt );
2830 - if( !$wgUser->isAllowed( 'reupload-shared' ) && !$destfile->exists() && wfFindFile( $nt ) ) {
 2898+ if ( !$wgUser->isAllowed( 'reupload-shared' ) && !$destfile->exists() && wfFindFile( $nt ) ) {
28312899 $errors[] = array( 'file-exists-sharedrepo' );
28322900 }
28332901
@@ -2834,21 +2902,21 @@
28352903
28362904 if ( $auth ) {
28372905 $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 ) );
28422910 }
28432911
28442912 $match = EditPage::matchSummarySpamRegex( $reason );
2845 - if( $match !== false ) {
 2913+ if ( $match !== false ) {
28462914 // This is kind of lame, won't display nice
2847 - $errors[] = array('spamprotectiontext');
 2915+ $errors[] = array( 'spamprotectiontext' );
28482916 }
28492917
28502918 $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 );
28532921 }
28542922
28552923 # The move is allowed only if (1) the target doesn't exist, or
@@ -2857,16 +2925,16 @@
28582926
28592927 if ( 0 != $newid ) { # Target exists; check for validity
28602928 if ( ! $this->isValidMoveTarget( $nt ) ) {
2861 - $errors[] = array('articleexists');
 2929+ $errors[] = array( 'articleexists' );
28622930 }
28632931 } else {
28642932 $tp = $nt->getTitleProtection();
28652933 $right = ( $tp['pt_create_perm'] == 'sysop' ) ? 'protect' : $tp['pt_create_perm'];
28662934 if ( $tp and !$wgUser->isAllowed( $right ) ) {
2867 - $errors[] = array('cantmove-titleprotected');
 2935+ $errors[] = array( 'cantmove-titleprotected' );
28682936 }
28692937 }
2870 - if(empty($errors))
 2938+ if ( empty( $errors ) )
28712939 return true;
28722940 return $errors;
28732941 }
@@ -2884,17 +2952,17 @@
28852953 */
28862954 public function moveTo( &$nt, $auth = true, $reason = '', $createRedirect = true ) {
28872955 $err = $this->isValidMoveOperation( $nt, $auth, $reason );
2888 - if( is_array( $err ) ) {
 2956+ if ( is_array( $err ) ) {
28892957 return $err;
28902958 }
28912959
28922960 // If it is a file, move it first. It is done before all other moving stuff is done because it's hard to revert
28932961 $dbw = wfGetDB( DB_MASTER );
2894 - if( $this->getNamespace() == NS_FILE ) {
 2962+ if ( $this->getNamespace() == NS_FILE ) {
28952963 $file = wfLocalFile( $this );
2896 - if( $file->exists() ) {
 2964+ if ( $file->exists() ) {
28972965 $status = $file->move( $nt );
2898 - if( !$status->isOk() ) {
 2966+ if ( !$status->isOk() ) {
28992967 return $status->getErrorsArray();
29002968 }
29012969 }
@@ -2902,15 +2970,15 @@
29032971
29042972 $pageid = $this->getArticleID();
29052973 $protected = $this->isProtected();
2906 - if( $nt->exists() ) {
 2974+ if ( $nt->exists() ) {
29072975 $err = $this->moveOverExistingRedirect( $nt, $reason, $createRedirect );
2908 - $pageCountChange = ($createRedirect ? 0 : -1);
 2976+ $pageCountChange = ( $createRedirect ? 0 : -1 );
29092977 } else { # Target didn't exist, do normal move.
29102978 $err = $this->moveToNewTitle( $nt, $reason, $createRedirect );
2911 - $pageCountChange = ($createRedirect ? 1 : 0);
 2979+ $pageCountChange = ( $createRedirect ? 1 : 0 );
29122980 }
29132981
2914 - if( is_array( $err ) ) {
 2982+ if ( is_array( $err ) ) {
29152983 return $err;
29162984 }
29172985 $redirid = $this->getArticleID();
@@ -2935,7 +3003,7 @@
29363004 'cl_sortkey' => $this->getPrefixedText() ),
29373005 __METHOD__ );
29383006
2939 - if( $protected ) {
 3007+ if ( $protected ) {
29403008 # Protect the redirect title as the title used to be...
29413009 $dbw->insertSelect( 'page_restrictions', 'page_restrictions',
29423010 array(
@@ -2953,8 +3021,8 @@
29543022 # Update the protection log
29553023 $log = new LogPage( 'protect' );
29563024 $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?
29593027 }
29603028
29613029 # Update watchlists
@@ -2963,7 +3031,7 @@
29643032 $oldtitle = $this->getDBkey();
29653033 $newtitle = $nt->getDBkey();
29663034
2967 - if( $oldnamespace != $newnamespace || $oldtitle != $newtitle ) {
 3035+ if ( $oldnamespace != $newnamespace || $oldtitle != $newtitle ) {
29683036 WatchedItem::duplicateEntries( $this, $nt );
29693037 }
29703038
@@ -2974,25 +3042,25 @@
29753043 $u->doUpdate();
29763044
29773045 # Update site_stats
2978 - if( $this->isContentPage() && !$nt->isContentPage() ) {
 3046+ if ( $this->isContentPage() && !$nt->isContentPage() ) {
29793047 # No longer a content page
29803048 # Not viewed, edited, removing
29813049 $u = new SiteStatsUpdate( 0, 1, -1, $pageCountChange );
2982 - } elseif( !$this->isContentPage() && $nt->isContentPage() ) {
 3050+ } elseif ( !$this->isContentPage() && $nt->isContentPage() ) {
29833051 # Now a content page
29843052 # 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 ) {
29873055 # Redirect added
29883056 $u = new SiteStatsUpdate( 0, 0, 0, 1 );
29893057 } else {
29903058 # Nothing special
29913059 $u = false;
29923060 }
2993 - if( $u )
 3061+ if ( $u )
29943062 $u->doUpdate();
29953063 # Update message cache for interface messages
2996 - if( $nt->getNamespace() == NS_MEDIAWIKI ) {
 3064+ if ( $nt->getNamespace() == NS_MEDIAWIKI ) {
29973065 global $wgMessageCache;
29983066
29993067 # @bug 17860: old article can be deleted, if this the case,
@@ -3053,7 +3121,7 @@
30543122 if ( !$dbw->cascadingDeletes() ) {
30553123 $dbw->delete( 'revision', array( 'rev_page' => $newid ), __METHOD__ );
30563124 global $wgUseTrackbacks;
3057 - if ($wgUseTrackbacks)
 3125+ if ( $wgUseTrackbacks )
30583126 $dbw->delete( 'trackbacks', array( 'tb_page' => $newid ), __METHOD__ );
30593127 $dbw->delete( 'pagelinks', array( 'pl_from' => $newid ), __METHOD__ );
30603128 $dbw->delete( 'imagelinks', array( 'il_from' => $newid ), __METHOD__ );
@@ -3074,12 +3142,12 @@
30753143 $nullRevId = $nullRevision->insertOn( $dbw );
30763144
30773145 $article = new Article( $this );
3078 - wfRunHooks( 'NewRevisionFromEditComplete', array($article, $nullRevision, $latest, $wgUser) );
 3146+ wfRunHooks( 'NewRevisionFromEditComplete', array( $article, $nullRevision, $latest, $wgUser ) );
30793147
30803148 # Change the name of the target page:
30813149 $dbw->update( 'page',
30823150 /* SET */ array(
3083 - 'page_touched' => $dbw->timestamp($now),
 3151+ 'page_touched' => $dbw->timestamp( $now ),
30843152 'page_namespace' => $nt->getNamespace(),
30853153 'page_title' => $nt->getDBkey(),
30863154 'page_latest' => $nullRevId,
@@ -3090,7 +3158,7 @@
30913159 $nt->resetArticleID( $oldid );
30923160
30933161 # Recreate the redirect, this time in the other direction.
3094 - if( $createRedirect || !$wgUser->isAllowed('suppressredirect') ) {
 3162+ if ( $createRedirect || !$wgUser->isAllowed( 'suppressredirect' ) ) {
30953163 $mwRedir = MagicWord::get( 'redirect' );
30963164 $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
30973165 $redirectArticle = new Article( $this );
@@ -3102,7 +3170,7 @@
31033171 $redirectRevision->insertOn( $dbw );
31043172 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
31053173
3106 - wfRunHooks( 'NewRevisionFromEditComplete', array($redirectArticle, $redirectRevision, false, $wgUser) );
 3174+ wfRunHooks( 'NewRevisionFromEditComplete', array( $redirectArticle, $redirectRevision, false, $wgUser ) );
31073175
31083176 # Now, we record the link from the redirect to the new title.
31093177 # It should have no other outgoing links...
@@ -3167,7 +3235,7 @@
31683236 $nullRevId = $nullRevision->insertOn( $dbw );
31693237
31703238 $article = new Article( $this );
3171 - wfRunHooks( 'NewRevisionFromEditComplete', array($article, $nullRevision, $latest, $wgUser) );
 3239+ wfRunHooks( 'NewRevisionFromEditComplete', array( $article, $nullRevision, $latest, $wgUser ) );
31723240
31733241 # Rename page entry
31743242 $dbw->update( 'page',
@@ -3182,7 +3250,7 @@
31833251 );
31843252 $nt->resetArticleID( $oldid );
31853253
3186 - if( $createRedirect || !$wgUser->isAllowed('suppressredirect') ) {
 3254+ if ( $createRedirect || !$wgUser->isAllowed( 'suppressredirect' ) ) {
31873255 # Insert redirect
31883256 $mwRedir = MagicWord::get( 'redirect' );
31893257 $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
@@ -3195,7 +3263,7 @@
31963264 $redirectRevision->insertOn( $dbw );
31973265 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
31983266
3199 - wfRunHooks( 'NewRevisionFromEditComplete', array($redirectArticle, $redirectRevision, false, $wgUser) );
 3267+ wfRunHooks( 'NewRevisionFromEditComplete', array( $redirectArticle, $redirectRevision, false, $wgUser ) );
32003268
32013269 # Record the just-created redirect's linking to the page
32023270 $dbw->insert( 'pagelinks',
@@ -3237,22 +3305,22 @@
32383306 public function moveSubpages( $nt, $auth = true, $reason = '', $createRedirect = true ) {
32393307 global $wgMaximumMovedPages;
32403308 // Check permissions
3241 - if( !$this->userCan( 'move-subpages' ) )
 3309+ if ( !$this->userCan( 'move-subpages' ) )
32423310 return array( 'cant-move-subpages' );
32433311 // Do the source and target namespaces support subpages?
3244 - if( !MWNamespace::hasSubpages( $this->getNamespace() ) )
 3312+ if ( !MWNamespace::hasSubpages( $this->getNamespace() ) )
32453313 return array( 'namespace-nosubpages',
32463314 MWNamespace::getCanonicalName( $this->getNamespace() ) );
3247 - if( !MWNamespace::hasSubpages( $nt->getNamespace() ) )
 3315+ if ( !MWNamespace::hasSubpages( $nt->getNamespace() ) )
32483316 return array( 'namespace-nosubpages',
32493317 MWNamespace::getCanonicalName( $nt->getNamespace() ) );
32503318
3251 - $subpages = $this->getSubpages($wgMaximumMovedPages + 1);
 3319+ $subpages = $this->getSubpages( $wgMaximumMovedPages + 1 );
32523320 $retval = array();
32533321 $count = 0;
3254 - foreach( $subpages as $oldSubpage ) {
 3322+ foreach ( $subpages as $oldSubpage ) {
32553323 $count++;
3256 - if( $count > $wgMaximumMovedPages ) {
 3324+ if ( $count > $wgMaximumMovedPages ) {
32573325 $retval[$oldSubpage->getPrefixedTitle()] =
32583326 array( 'movepage-max-pages',
32593327 $wgMaximumMovedPages );
@@ -3262,16 +3330,16 @@
32633331 // We don't know whether this function was called before
32643332 // or after moving the root page, so check both
32653333 // $this and $nt
3266 - if( $oldSubpage->getArticleId() == $this->getArticleId() ||
 3334+ if ( $oldSubpage->getArticleId() == $this->getArticleId() ||
32673335 $oldSubpage->getArticleID() == $nt->getArticleId() )
32683336 // When moving a page to a subpage of itself,
32693337 // don't move it twice
32703338 continue;
32713339 $newPageName = preg_replace(
3272 - '#^'.preg_quote( $this->getDBkey(), '#' ).'#',
 3340+ '#^' . preg_quote( $this->getDBkey(), '#' ) . '#',
32733341 StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # bug 21234
32743342 $oldSubpage->getDBkey() );
3275 - if( $oldSubpage->isTalkPage() ) {
 3343+ if ( $oldSubpage->isTalkPage() ) {
32763344 $newNs = $nt->getTalkPage()->getNamespace();
32773345 } else {
32783346 $newNs = $nt->getSubjectPage()->getNamespace();
@@ -3281,7 +3349,7 @@
32823350 $newSubpage = Title::makeTitleSafe( $newNs, $newPageName );
32833351
32843352 $success = $oldSubpage->moveTo( $newSubpage, $auth, $reason, $createRedirect );
3285 - if( $success === true ) {
 3353+ if ( $success === true ) {
32863354 $retval[$oldSubpage->getPrefixedText()] = $newSubpage->getPrefixedText();
32873355 } else {
32883356 $retval[$oldSubpage->getPrefixedText()] = $success;
@@ -3306,14 +3374,14 @@
33073375 array( 'FOR UPDATE' )
33083376 );
33093377 # Cache some fields we may want
3310 - $this->mArticleID = $row ? intval($row->page_id) : 0;
 3378+ $this->mArticleID = $row ? intval( $row->page_id ) : 0;
33113379 $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 ) {
33143382 return false;
33153383 }
33163384 # Does the article have a history?
3317 - $row = $dbw->selectField( array( 'page', 'revision'),
 3385+ $row = $dbw->selectField( array( 'page', 'revision' ),
33183386 'rev_id',
33193387 array( 'page_namespace' => $this->getNamespace(),
33203388 'page_title' => $this->getDBkey(),
@@ -3324,7 +3392,7 @@
33253393 array( 'FOR UPDATE' )
33263394 );
33273395 # Return true if there was no history
3328 - return ($row === false);
 3396+ return ( $row === false );
33293397 }
33303398
33313399 /**
@@ -3337,15 +3405,15 @@
33383406 public function isValidMoveTarget( $nt ) {
33393407 $dbw = wfGetDB( DB_MASTER );
33403408 # Is it an existsing file?
3341 - if( $nt->getNamespace() == NS_FILE ) {
 3409+ if ( $nt->getNamespace() == NS_FILE ) {
33423410 $file = wfLocalFile( $nt );
3343 - if( $file->exists() ) {
 3411+ if ( $file->exists() ) {
33443412 wfDebug( __METHOD__ . ": file exists\n" );
33453413 return false;
33463414 }
33473415 }
33483416 # Is it a redirect with no history?
3349 - if( !$nt->isSingleRevRedirect() ) {
 3417+ if ( !$nt->isSingleRevRedirect() ) {
33503418 wfDebug( __METHOD__ . ": not a one-rev redirect\n" );
33513419 return false;
33523420 }
@@ -3357,7 +3425,7 @@
33583426 $m = array();
33593427 if ( preg_match( "/\\[\\[\\s*([^\\]\\|]*)]]/", $text, $m ) ) {
33603428 $redirTitle = Title::newFromText( $m[1] );
3361 - if( !is_object( $redirTitle ) ||
 3429+ if ( !is_object( $redirTitle ) ||
33623430 ( $redirTitle->getPrefixedDBkey() != $this->getPrefixedDBkey() &&
33633431 $redirTitle->getPrefixedDBkey() != $nt->getPrefixedDBkey() ) ) {
33643432 wfDebug( __METHOD__ . ": redirect points to other page\n" );
@@ -3396,16 +3464,16 @@
33973465
33983466 # NEW SQL
33993467 $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";
34033471
34043472 $res = $dbr->query( $sql );
34053473
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();
34103478 $dbr->freeResult( $res );
34113479 } else {
34123480 $data = array();
@@ -3423,15 +3491,15 @@
34243492 $stack = array();
34253493 $parents = $this->getParentCategories();
34263494
3427 - if( $parents ) {
3428 - foreach( $parents as $parent => $current ) {
 3495+ if ( $parents ) {
 3496+ foreach ( $parents as $parent => $current ) {
34293497 if ( array_key_exists( $parent, $children ) ) {
34303498 # Circular reference
34313499 $stack[$parent] = array();
34323500 } else {
3433 - $nt = Title::newFromText($parent);
 3501+ $nt = Title::newFromText( $parent );
34343502 if ( $nt ) {
3435 - $stack[$parent] = $nt->getParentCategoryTree( $children + array($parent => 1) );
 3503+ $stack[$parent] = $nt->getParentCategoryTree( $children + array( $parent => 1 ) );
34363504 }
34373505 }
34383506 }
@@ -3449,7 +3517,7 @@
34503518 * @return \type{\array} Selection array
34513519 */
34523520 public function pageCond() {
3453 - if( $this->mArticleID > 0 ) {
 3521+ if ( $this->mArticleID > 0 ) {
34543522 // PK avoids secondary lookups in InnoDB, shouldn't hurt other DBs
34553523 return array( 'page_id' => $this->mArticleID );
34563524 } else {
@@ -3464,11 +3532,11 @@
34653533 * @param $flags \type{\int} GAID_FOR_UPDATE
34663534 * @return \twotypes{\int,\bool} Old revision ID, or FALSE if none exists
34673535 */
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 );
34703538 return $db->selectField( 'revision', 'rev_id',
34713539 array(
3472 - 'rev_page' => $this->getArticleId($flags),
 3540+ 'rev_page' => $this->getArticleId( $flags ),
34733541 'rev_id < ' . intval( $revId )
34743542 ),
34753543 __METHOD__,
@@ -3483,11 +3551,11 @@
34843552 * @param $flags \type{\int} GAID_FOR_UPDATE
34853553 * @return \twotypes{\int,\bool} Next revision ID, or FALSE if none exists
34863554 */
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 );
34893557 return $db->selectField( 'revision', 'rev_id',
34903558 array(
3491 - 'rev_page' => $this->getArticleId($flags),
 3559+ 'rev_page' => $this->getArticleId( $flags ),
34923560 'rev_id > ' . intval( $revId )
34933561 ),
34943562 __METHOD__,
@@ -3501,16 +3569,16 @@
35023570 * @param $flags \type{\int} GAID_FOR_UPDATE
35033571 * @return Revision (or NULL if page doesn't exist)
35043572 */
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;
35093577 $row = $db->selectRow( 'revision', '*',
35103578 array( 'rev_page' => $pageId ),
35113579 __METHOD__,
35123580 array( 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 1 )
35133581 );
3514 - if( !$row ) {
 3582+ if ( !$row ) {
35153583 return null;
35163584 } else {
35173585 return new Revision( $row );
@@ -3534,7 +3602,7 @@
35353603 */
35363604 public function getEarliestRevTime() {
35373605 $dbr = wfGetDB( DB_SLAVE );
3538 - if( $this->exists() ) {
 3606+ if ( $this->exists() ) {
35393607 $min = $dbr->selectField( 'revision',
35403608 'MIN(rev_timestamp)',
35413609 array( 'rev_page' => $this->getArticleId() ),
@@ -3581,7 +3649,7 @@
35823650 * @return Integer: result of string comparison, or namespace comparison
35833651 */
35843652 public static function compare( $a, $b ) {
3585 - if( $a->getNamespace() == $b->getNamespace() ) {
 3653+ if ( $a->getNamespace() == $b->getNamespace() ) {
35863654 return strcmp( $a->getText(), $b->getText() );
35873655 } else {
35883656 return $a->getNamespace() - $b->getNamespace();
@@ -3627,7 +3695,7 @@
36283696 * @return \type{\bool}
36293697 */
36303698 public function isAlwaysKnown() {
3631 - if( $this->mInterwiki != '' ) {
 3699+ if ( $this->mInterwiki != '' ) {
36323700 return true; // any interwiki link might be viewable, for all we know
36333701 }
36343702 switch( $this->mNamespace ) {
@@ -3690,7 +3758,7 @@
36913759 * @internal note -- uses hardcoded namespace index instead of constants
36923760 */
36933761 public function canExist() {
3694 - return $this->mNamespace >=0 && $this->mNamespace != NS_MEDIA;
 3762+ return $this->mNamespace >= 0 && $this->mNamespace != NS_MEDIA;
36953763 }
36963764
36973765 /**
@@ -3715,7 +3783,7 @@
37163784 * @return \type{\string} Last touched timestamp
37173785 */
37183786 public function getTouched( $db = null ) {
3719 - $db = isset($db) ? $db : wfGetDB( DB_SLAVE );
 3787+ $db = isset( $db ) ? $db : wfGetDB( DB_SLAVE );
37203788 $touched = $db->selectField( 'page', 'page_touched', $this->pageCond(), __METHOD__ );
37213789 return $touched;
37223790 }
@@ -3729,17 +3797,17 @@
37303798 public function getNotificationTimestamp( $user = null ) {
37313799 global $wgUser, $wgShowUpdatedMarker;
37323800 // Assume current user if none given
3733 - if( !$user ) $user = $wgUser;
 3801+ if ( !$user ) $user = $wgUser;
37343802 // Check cache first
37353803 $uid = $user->getId();
3736 - if( isset($this->mNotificationTimestamp[$uid]) ) {
 3804+ if ( isset( $this->mNotificationTimestamp[$uid] ) ) {
37373805 return $this->mNotificationTimestamp[$uid];
37383806 }
3739 - if( !$uid || !$wgShowUpdatedMarker ) {
 3807+ if ( !$uid || !$wgShowUpdatedMarker ) {
37403808 return $this->mNotificationTimestamp[$uid] = false;
37413809 }
37423810 // Don't cache too much!
3743 - if( count($this->mNotificationTimestamp) >= self::CACHE_MAX ) {
 3811+ if ( count( $this->mNotificationTimestamp ) >= self::CACHE_MAX ) {
37443812 $this->mNotificationTimestamp = array();
37453813 }
37463814 $dbr = wfGetDB( DB_SLAVE );
@@ -3763,7 +3831,7 @@
37643832 global $wgScriptPath, $wgServer, $wgScriptExtension;
37653833
37663834 return "$wgServer$wgScriptPath/trackback$wgScriptExtension?article="
3767 - . htmlspecialchars(urlencode($this->getPrefixedDBkey()));
 3835+ . htmlspecialchars( urlencode( $this->getPrefixedDBkey() ) );
37683836 }
37693837
37703838 /**
@@ -3772,8 +3840,8 @@
37733841 * @return \type{\string} Trackback RDF
37743842 */
37753843 public function trackbackRDF() {
3776 - $url = htmlspecialchars($this->getFullURL());
3777 - $title = htmlspecialchars($this->getText());
 3844+ $url = htmlspecialchars( $this->getFullURL() );
 3845+ $title = htmlspecialchars( $this->getText() );
37783846 $tburl = $this->trackbackURL();
37793847
37803848 // Autodiscovery RDF is placed in comments so HTML validator
@@ -3896,7 +3964,7 @@
38973965 'rd_title' => $this->getDBkey(),
38983966 'rd_from = page_id'
38993967 );
3900 - if ( !is_null($ns) ) $where['page_namespace'] = $ns;
 3968+ if ( !is_null( $ns ) ) $where['page_namespace'] = $ns;
39013969
39023970 $res = $dbr->select(
39033971 array( 'redirect', 'page' ),
@@ -3906,7 +3974,7 @@
39073975 );
39083976
39093977
3910 - foreach( $res as $row ) {
 3978+ foreach ( $res as $row ) {
39113979 $redirs[] = self::newFromRow( $row );
39123980 }
39133981 return $redirs;
@@ -3921,12 +3989,12 @@
39223990 global $wgInvalidRedirectTargets;
39233991
39243992 // invalid redirect targets are stored in a global array, but explicity disallow Userlogout here
3925 - if( $this->isSpecial( 'Userlogout' ) ) {
 3993+ if ( $this->isSpecial( 'Userlogout' ) ) {
39263994 return false;
39273995 }
39283996
3929 - foreach( $wgInvalidRedirectTargets as $target ) {
3930 - if( $this->isSpecial( $target ) ) {
 3997+ foreach ( $wgInvalidRedirectTargets as $target ) {
 3998+ if ( $this->isSpecial( $target ) ) {
39313999 return false;
39324000 }
39334001 }
@@ -3952,7 +4020,7 @@
39534021 *
39544022 * @return Boolean
39554023 */
3956 - public function canUseNoindex(){
 4024+ public function canUseNoindex() {
39574025 global $wgArticleRobotPolicies, $wgContentNamespaces,
39584026 $wgExemptFromUserRobotsControl;
39594027
@@ -3971,7 +4039,7 @@
39724040 */
39734041 public function getRestrictionTypes() {
39744042 global $wgRestrictionTypes;
3975 - $types = $this->exists() ? $wgRestrictionTypes : array('create');
 4043+ $types = $this->exists() ? $wgRestrictionTypes : array( 'create' );
39764044
39774045 if ( $this->getNamespace() == NS_FILE ) {
39784046 $types[] = 'upload';

Follow-up revisions

RevisionCommit summaryAuthorDate
r72323Follow-up r65504. Use canonical class name.platonides22:07, 3 September 2010
r77243followup r65504 — actually check that we hav errors before returnning from ...mah19:52, 24 November 2010
r87326Fix Bug 28354: Edit tab is shown as "view source" for blocked users, which br...pcopp13:18, 3 May 2011
r90410Remove another empty test, courtesy of r65504.demon18:46, 19 June 2011

Comments

#Comment by MaxSem (talk | contribs)   11:33, 24 April 2010

Please, please, please. Don't mix code changes with whitespace ones, they're much harder to review this way.

#Comment by Yaron Koren (talk | contribs)   17:54, 24 November 2010

This set of changes to Title.php had the unfortunate effect of making a call to userCan( 'edit' ) fail if $wgEmailConfirmToEdit is set to true - it returns true even though it should return false. The problem is that userCan() calls the permissions checks with $short = true, which means that the check of $wgEmailConfirmToEdit gets bypassed altogether. Please fix this, somehow...

#Comment by Yaron Koren (talk | contribs)   00:37, 10 December 2010

It's worse than I thought - it looks like userCan('read') is now messed up as well, at least when using the SimpleSecurity extension.

#Comment by MarkAHershberger (talk | contribs)   20:08, 6 January 2011

See r77243 and r77316

#Comment by Yaron Koren (talk | contribs)   00:03, 7 January 2011

Cool - but that didn't take care of the userCan('read') problem, did it? It's still a problem when I try it.

#Comment by MarkAHershberger (talk | contribs)   00:52, 7 January 2011

Well, it has been more than a day since I committed those. Are you testing trunk?

#Comment by Yaron Koren (talk | contribs)   01:02, 7 January 2011

Yeah - I just updated to the latest trunk version again, and userCan( 'read' ) always returns true, even when I've disabled reading using SimpleSecurity.

#Comment by Catrope (talk | contribs)   00:25, 27 January 2011

SimpleSecurity doesn't use any of the hooks associated with userCan, but instead uses the UserGetRights hook in a way that seems to be specifically geared (I mean, hacked) towards the implementation of Title::userCan. The breakage you're talking about is most likely a problem with SimpleSecurity.

Status & tagging log