r54527 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54526‎ | r54527 | r54528 >
Date:16:26, 6 August 2009
Author:werdna
Status:ok
Tags:
Comment:
* Fail fast on trying to find create restrictions for pages that exist.
* Break out loadRestrictionsFromRow into a new function loadRestrictionsFromRows (which actually accepts an array of rows, unlike the original), and loadRestrictionsFromResultWrapper, which has the semantics of the old function (and wraps around loadRestrictionsFromRows).
Modified paths:
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Title.php
@@ -1398,6 +1398,11 @@
13991399 if ( $this->getNamespace() < 0 ) {
14001400 return false;
14011401 }
 1402+
 1403+ // Can't protect pages that exist.
 1404+ if ($this->exists()) {
 1405+ return false;
 1406+ }
14021407
14031408 $dbr = wfGetDB( DB_SLAVE );
14041409 $res = $dbr->select( 'protected_titles', '*',
@@ -1857,7 +1862,18 @@
18581863 * Loads a string into mRestrictions array
18591864 * @param $res \type{Resource} restrictions as an SQL result.
18601865 */
1861 - private function loadRestrictionsFromRow( $res, $oldFashionedRestrictions = NULL ) {
 1866+ private function loadRestrictionsFromResultWrapper( $res, $oldFashionedRestrictions = NULL ) {
 1867+ $rows = array();
 1868+ $dbr = wfGetDB( DB_SLAVE );
 1869+
 1870+ while( $row = $dbr->fetchObject( $res ) ) {
 1871+ $rows[] = $row;
 1872+ }
 1873+
 1874+ $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions );
 1875+ }
 1876+
 1877+ public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = NULL ) {
18621878 global $wgRestrictionTypes;
18631879 $dbr = wfGetDB( DB_SLAVE );
18641880
@@ -1892,12 +1908,12 @@
18931909
18941910 }
18951911
1896 - if( $dbr->numRows( $res ) ) {
 1912+ if( count($rows) ) {
18971913 # Current system - load second to make them override.
18981914 $now = wfTimestampNow();
18991915 $purgeExpired = false;
19001916
1901 - foreach( $res as $row ) {
 1917+ foreach( $rows as $row ) {
19021918 # Cycle through all the restrictions.
19031919
19041920 // Don't take care of restrictions types that aren't in $wgRestrictionTypes
@@ -1939,7 +1955,7 @@
19401956 $res = $dbr->select( 'page_restrictions', '*',
19411957 array ( 'pr_page' => $this->getArticleId() ), __METHOD__ );
19421958
1943 - $this->loadRestrictionsFromRow( $res, $oldFashionedRestrictions );
 1959+ $this->loadRestrictionsFromResultWrapper( $res, $oldFashionedRestrictions );
19441960 } else {
19451961 $title_protection = $this->getTitleProtection();
19461962

Follow-up revisions

RevisionCommit summaryAuthorDate
r79759Address my r76242 fixme....platonides21:26, 6 January 2011

Status & tagging log