r19062 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r19061‎ | r19062 | r19063 >
Date:14:50, 10 January 2007
Author:werdna
Status:old
Tags:
Comment:
* REFACTOR restrictions-loading from database in Title::getRestrictions into Title::loadRestrictions, moving the original loadRestrictions to loadRestrictionsFromRow -- no references found to loadRestrictions outside of Title.php; where the two references were updated or refactored.
* Optimised the cascading protection code in Parser.php to only update templatelinks once per page, as opposed to once per changed template per page.
Modified paths:
  • /branches/werdna/restrictions-separation/includes/Parser.php (modified) (history)
  • /branches/werdna/restrictions-separation/includes/Title.php (modified) (history)

Diff [purge]

Index: branches/werdna/restrictions-separation/includes/Parser.php
@@ -94,7 +94,8 @@
9595 * @private
9696 */
9797 # Persistent:
98 - var $mTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables, $mTlUpdatePages;
 98+ var $mTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables;
 99+ var $mTlDoneUpdateFor;
99100
100101 # Cleared with clearState():
101102 var $mOutput, $mAutonumber, $mDTopen, $mStripState;
@@ -3064,17 +3065,18 @@
30653066 $title = Title::newFromText( $part1, $ns );
30663067
30673068 # If this page is subject to cascading restrictions, check that the template is included in templatelinks
3068 - if ($this->mTitle->areRestrictionsCascading()) {
 3069+ if ( $this->mTitle->areRestrictionsCascading( ) ) {
30693070 # Subject to cascading restrictions. Check for templatelinks entry
30703071
3071 - # Use mTlUpdatePages to avoid recursion.
3072 - if (!$this->mTlUpdatePages) {
3073 - $this->mTlUpdatePages = array ();
 3072+ $res = in_array( $part1, $this->mTlTemplates );
 3073+
 3074+ if ( !is_array( $this->mTlDoneUpdateFor ) ) {
 3075+ $this->mTlDoneUpdateFor = array ();
30743076 }
30753077
3076 - $res = in_array($part1, $this->mTlTemplates);
 3078+ if ( !$res && !in_array( $this->mTitle->getPrefixedText(), $this->mTlDoneUpdateFor ) ) {
 3079+ $this->mTlDoneUpdateFor[] = $this->mTitle->getPrefixedText();
30773080
3078 - if (!$res && !in_array($this->mTitle->getPrefixedText(), $this->mTlUpdatePages)) {
30793081 $cc_article = new Article( $this->mTitle );
30803082
30813083 # This title needs a templatelinks refresh. Do it now.
Index: branches/werdna/restrictions-separation/includes/Title.php
@@ -1388,7 +1388,7 @@
13891389 * @param resource $res restrictions as an SQL result.
13901390 * @access public
13911391 */
1392 - function loadRestrictions( $res ) {
 1392+ function loadRestrictionsFromRow( $res ) {
13931393 $dbr =& wfGetDb( DB_SLAVE );
13941394
13951395 if (!$dbr->numRows( $res ) ) {
@@ -1413,6 +1413,16 @@
14141414 $this->mRestrictionsLoaded = true;
14151415 }
14161416
 1417+ function loadRestrictions() {
 1418+ if( !$this->mRestrictionsLoaded ) {
 1419+ $dbr =& wfGetDB( DB_SLAVE );
 1420+
 1421+ $res = $dbr->select( 'page_restrictions', '*',
 1422+ array ( 'pr_page' => $this->getArticleId() ), __METHOD__ );
 1423+ $this->loadRestrictionsFromRow( $res );
 1424+ }
 1425+ }
 1426+
14171427 /**
14181428 * Accessor/initialisation for mRestrictions
14191429 *
@@ -1423,11 +1433,7 @@
14241434 function getRestrictions( $action ) {
14251435 if( $this->exists() ) {
14261436 if( !$this->mRestrictionsLoaded ) {
1427 - $dbr =& wfGetDB( DB_SLAVE );
1428 -
1429 - $res = $dbr->select( 'page_restrictions', '*',
1430 - array ( 'pr_page' => $this->getArticleId() ), __METHOD__ );
1431 - $this->loadRestrictions( $res );
 1437+ $this->loadRestrictions();
14321438 }
14331439 return isset( $this->mRestrictions[$action] )
14341440 ? $this->mRestrictions[$action]