r33133 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r33132‎ | r33133 | r33134 >
Date:15:20, 11 April 2008
Author:catrope
Status:old
Tags:
Comment:
Committing patch for bug 10931, which also fixes bug 13651. For a detailed explanation of what this commit does, see bug 10931 comment #24
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/api/ApiBlock.php (modified) (history)
  • /trunk/phase3/includes/api/ApiDelete.php (modified) (history)
  • /trunk/phase3/includes/api/ApiEditPage.php (modified) (history)
  • /trunk/phase3/includes/api/ApiMain.php (modified) (history)
  • /trunk/phase3/includes/api/ApiMove.php (modified) (history)
  • /trunk/phase3/includes/api/ApiPageSet.php (modified) (history)
  • /trunk/phase3/includes/api/ApiProtect.php (modified) (history)
  • /trunk/phase3/includes/api/ApiRollback.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUnblock.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUndelete.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -34,6 +34,7 @@
3535 var $mTouched; //!<
3636 var $mUser; //!<
3737 var $mUserText; //!<
 38+ var $mRedirectTarget; //!<
3839 /**@}}*/
3940
4041 /**
@@ -57,11 +58,57 @@
5859 }
5960
6061 /**
 62+ * If this page is a redirect, get its target
 63+ *
 64+ * The target will be fetched from the redirect table if possible.
 65+ * If this page doesn't have an entry there, call insertRedirect()
 66+ * @return mixed Title object, or null if this page is not a redirect
 67+ */
 68+ public function getRedirectTarget() {
 69+ if(!$this->mTitle || !$this->mTitle->isRedirect())
 70+ return null;
 71+ if(!is_null($this->mRedirectTarget))
 72+ return $this->mRedirectTarget;
 73+
 74+ # Query the redirect table
 75+ $dbr = wfGetDb(DB_SLAVE);
 76+ $res = $dbr->select('redirect',
 77+ array('rd_namespace', 'rd_title'),
 78+ array('rd_from' => $this->getID()),
 79+ __METHOD__
 80+ );
 81+ $row = $dbr->fetchObject($res);
 82+ if($row)
 83+ return $this->mRedirectTarget = Title::makeTitle($row->rd_namespace, $row->rd_title);
 84+
 85+ # This page doesn't have an entry in the redirect table
 86+ return $this->mRedirectTarget = $this->insertRedirect();
 87+ }
 88+
 89+ /**
 90+ * Insert an entry for this page into the redirect table.
 91+ *
 92+ * Don't call this function directly unless you know what you're doing.
 93+ * @return Title object
 94+ */
 95+ public function insertRedirect() {
 96+ $retval = Title::newFromRedirect($this->getContent());
 97+ if(!$retval)
 98+ return null;
 99+ $dbw = wfGetDb(DB_MASTER);
 100+ $dbw->insert('redirect', array(
 101+ 'rd_from' => $this->getID(),
 102+ 'rd_namespace' => $retval->getNamespace(),
 103+ 'rd_title' => $retval->getDBKey()
 104+ ));
 105+ return $retval;
 106+ }
 107+
 108+ /**
61109 * @return mixed false, Title of in-wiki target, or string with URL
62110 */
63111 function followRedirect() {
64 - $text = $this->getContent();
65 - $rt = Title::newFromRedirect( $text );
 112+ $rt = $this->getRedirectTarget();
66113
67114 # process if title object is valid and not special:userlogout
68115 if( $rt ) {
@@ -114,6 +161,7 @@
115162
116163 $this->mCurID = $this->mUser = $this->mCounter = -1; # Not loaded
117164 $this->mRedirectedFrom = null; # Title object if set
 165+ $this->mRedirectTarget = null; # Title object if set
118166 $this->mUserText =
119167 $this->mTimestamp = $this->mComment = '';
120168 $this->mGoodAdjustment = $this->mTotalAdjustment = 0;
@@ -801,7 +849,7 @@
802850
803851 }
804852
805 - elseif ( $rt = Title::newFromRedirect( $text ) ) {
 853+ elseif ( $rt = $this->getRedirectTarget() ) {
806854 # Display redirect
807855 $imageDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
808856 $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
Index: trunk/phase3/includes/api/ApiMove.php
@@ -79,8 +79,6 @@
8080 // We don't care about multiple errors, just report one of them
8181 $this->dieUsageMsg(current($errors));
8282
83 - $dbw = wfGetDB(DB_MASTER);
84 - $dbw->begin();
8583 $retval = $fromTitle->moveTo($toTitle, true, $params['reason'], !$params['noredirect']);
8684 if($retval !== true)
8785 $this->dieUsageMsg(array($retval));
@@ -118,7 +116,7 @@
119117 $wgUser->removeWatch($fromTitle);
120118 $wgUser->removeWatch($toTitle);
121119 }
122 - $dbw->commit(); // Make sure all changes are really written to the DB
 120+ $this->getMain()->scheduleCommit();
123121 $this->getResult()->addValue(null, $this->getModuleName(), $r);
124122 }
125123
Index: trunk/phase3/includes/api/ApiProtect.php
@@ -85,8 +85,6 @@
8686 $this->dieUsageMsg(array('missingtitles-createonly'));
8787 }
8888
89 - $dbw = wfGetDb(DB_MASTER);
90 - $dbw->begin();
9189 if($titleObj->exists()) {
9290 $articleObj = new Article($titleObj);
9391 $ok = $articleObj->updateRestrictions($protections, $params['reason'], $params['cascade'], $expiry);
@@ -96,7 +94,7 @@
9795 // This is very weird. Maybe the article was deleted or the user was blocked/desysopped in the meantime?
9896 // Just throw an unknown error in this case, as it's very likely to be a race condition
9997 $this->dieUsageMsg(array());
100 - $dbw->commit();
 98+ $this->getMain()->scheduleCommit();
10199 $res = array('title' => $titleObj->getPrefixedText(), 'reason' => $params['reason']);
102100 if($expiry == Block::infinity())
103101 $res['expiry'] = 'infinity';
Index: trunk/phase3/includes/api/ApiMain.php
@@ -95,7 +95,7 @@
9696 'dbgfm' => 'ApiFormatDbg'
9797 );
9898
99 - private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames;
 99+ private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames, $mCommit;
100100 private $mResult, $mAction, $mShowVersions, $mEnableWrite, $mRequest, $mInternalMode, $mSquidMaxage;
101101
102102 /**
@@ -150,6 +150,7 @@
151151 $this->mRequest = & $request;
152152
153153 $this->mSquidMaxage = 0;
 154+ $this->mCommit = false;
154155 }
155156
156157 /**
@@ -195,6 +196,13 @@
196197 public function createPrinterByName($format) {
197198 return new $this->mFormats[$format] ($this, $format);
198199 }
 200+
 201+ /**
 202+ * Schedule a database commit
 203+ */
 204+ public function scheduleCommit() {
 205+ $this->mCommit = true;
 206+ }
199207
200208 /**
201209 * Execute api request. Any errors will be handled if the API was called by the remote client.
@@ -205,6 +213,11 @@
206214 $this->executeAction();
207215 else
208216 $this->executeActionWithErrorHandling();
 217+ if($this->mCommit)
 218+ {
 219+ $dbw = wfGetDb(DB_MASTER);
 220+ $dbw->immediateCommit();
 221+ }
209222 $this->profileOut();
210223 }
211224
@@ -617,3 +630,4 @@
618631 }
619632
620633
 634+
Index: trunk/phase3/includes/api/ApiPageSet.php
@@ -528,7 +528,7 @@
529529 while($row = $db->fetchObject($res))
530530 {
531531 $rdfrom = intval($row->rd_from);
532 - $from = Title::newFromId($row->rd_from)->getPrefixedText();
 532+ $from = $this->mPendingRedirectIDs[$rdfrom]->getPrefixedText();
533533 $to = Title::makeTitle($row->rd_namespace, $row->rd_title)->getPrefixedText();
534534 unset($this->mPendingRedirectIDs[$rdfrom]);
535535 if(!isset($this->mAllPages[$row->rd_namespace][$row->rd_title]))
@@ -537,7 +537,22 @@
538538 }
539539 $db->freeResult($res);
540540 if(!empty($this->mPendingRedirectIDs))
541 - ApiBase :: dieDebug(__METHOD__, 'Invalid redirect IDs were found');
 541+ {
 542+ # We found pages that aren't in the redirect table
 543+ # Add them
 544+ foreach($this->mPendingRedirectIDs as $id => $title)
 545+ {
 546+ $article = new Article($title);
 547+ $rt = $article->insertRedirect();
 548+ if(!$rt)
 549+ # What the hell. Let's just ignore this
 550+ continue;
 551+ $lb->addObj($rt);
 552+ $this->mRedirectTitles[$title->getPrefixedText()] = $rt->getPrefixedText();
 553+ unset($this->mPendingRedirectIDs[$id]);
 554+ }
 555+ $this->getMain()->scheduleCommit();
 556+ }
542557 return $lb;
543558 }
544559
@@ -617,3 +632,4 @@
618633 }
619634 }
620635
 636+
Index: trunk/phase3/includes/api/ApiRollback.php
@@ -62,15 +62,13 @@
6363 $articleObj = new Article($titleObj);
6464 $summary = (isset($params['summary']) ? $params['summary'] : "");
6565 $details = null;
66 - $dbw = wfGetDb(DB_MASTER);
67 - $dbw->begin();
6866 $retval = $articleObj->doRollback($username, $summary, $params['token'], $params['markbot'], $details);
6967
7068 if(!empty($retval))
7169 // We don't care about multiple errors, just report one of them
7270 $this->dieUsageMsg(current($retval));
7371
74 - $dbw->commit();
 72+ $this->getMain()->scheduleCommit();
7573 $current = $target = $summary = NULL;
7674 extract($details);
7775
Index: trunk/phase3/includes/api/ApiBlock.php
@@ -87,14 +87,12 @@
8888 $form->BlockEmail = $params['noemail'];
8989 $form->BlockHideName = $params['hidename'];
9090
91 - $dbw = wfGetDb(DB_MASTER);
92 - $dbw->begin();
9391 $retval = $form->doBlock($userID, $expiry);
9492 if(!empty($retval))
9593 // We don't care about multiple errors, just report one of them
9694 $this->dieUsageMsg($retval);
 95+ $this->getMain()->scheduleCommit();
9796
98 - $dbw->commit();
9997 $res['user'] = $params['user'];
10098 $res['userID'] = $userID;
10199 $res['expiry'] = ($expiry == Block::infinity() ? 'infinite' : $expiry);
Index: trunk/phase3/includes/api/ApiDelete.php
@@ -66,8 +66,6 @@
6767
6868 $articleObj = new Article($titleObj);
6969 $reason = (isset($params['reason']) ? $params['reason'] : NULL);
70 - $dbw = wfGetDb(DB_MASTER);
71 - $dbw->begin();
7270 $retval = self::delete($articleObj, $params['token'], $reason);
7371
7472 if(!empty($retval))
@@ -78,7 +76,7 @@
7977 $articleObj->doWatch();
8078 else if($params['unwatch'])
8179 $articleObj->doUnwatch();
82 - $dbw->commit();
 80+ $this->getMain()->scheduleCommit();
8381 $r = array('title' => $titleObj->getPrefixedText(), 'reason' => $reason);
8482 $this->getResult()->addValue(null, $this->getModuleName(), $r);
8583 }
Index: trunk/phase3/includes/api/ApiUndelete.php
@@ -73,7 +73,7 @@
7474 if(!is_array($retval))
7575 $this->dieUsageMsg(array('cannotundelete'));
7676
77 - $dbw->commit();
 77+ $this->getMain()->scheduleCommit();
7878 $info['title'] = $titleObj->getPrefixedText();
7979 $info['revisions'] = $retval[0];
8080 $info['fileversions'] = $retval[1];
Index: trunk/phase3/includes/api/ApiEditPage.php
@@ -146,10 +146,8 @@
147147 # but that breaks API mode detection through is_null($wgTitle)
148148 global $wgTitle;
149149 $wgTitle = null;
150 - $dbw = wfGetDb(DB_MASTER);
151 - $dbw->begin();
152150 $retval = $ep->internalAttemptSave($result, $wgUser->isAllowed('bot') && $params['bot']);
153 - $dbw->commit();
 151+ $this->getMain()->scheduleCommit();
154152 switch($retval)
155153 {
156154 case EditPage::AS_HOOK_ERROR:
Index: trunk/phase3/includes/api/ApiUnblock.php
@@ -70,13 +70,11 @@
7171 $id = $params['id'];
7272 $user = $params['user'];
7373 $reason = (is_null($params['reason']) ? '' : $params['reason']);
74 - $dbw = wfGetDb(DB_MASTER);
75 - $dbw->begin();
7674 $retval = IPUnblockForm::doUnblock($id, $user, $reason, $range);
7775 if(!empty($retval))
7876 $this->dieUsageMsg($retval);
7977
80 - $dbw->commit();
 78+ $this->getMain()->scheduleCommit();
8179 $res['id'] = $id;
8280 $res['user'] = $user;
8381 $res['reason'] = $reason;
Index: trunk/phase3/RELEASE-NOTES
@@ -69,6 +69,7 @@
7070 to message 'sidebar'
7171 ** (bug 6332) Lacking entry Mainpage-url
7272 ** (bug 8617) Separate main page url and name
 73+* Automatically add old redirects to the redirect table when needed
7374
7475 === Bug fixes in 1.13 ===
7576

Follow-up revisions

RevisionCommit summaryAuthorDate
r33381Revert some chunks of r33133 and r33375:...brion18:11, 15 April 2008
r33383(bug 13745) Fix regression from r33133 by changing INSERT to REPLACEcatrope18:32, 15 April 2008
r69181Followup to r51583: actually use the rd_interwiki and rd_fragment fields, in ...catrope10:49, 8 July 2010

Status & tagging log