r17085 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17084‎ | r17085 | r17086 >
Date:10:35, 18 October 2006
Author:proes
Status:old
Tags:
Comment:
Streamlined save procedure to prevent erroneous edit conflicts. Two users editing the same page should be a lot safer now. Previously the changes of user A would be undone by the changes of user B when B saved after A, even when user B only worked on different parts of the page user A worked on. Now only true edit conflicts should occur when user A and user B worked on the same parts of a page at roughly the same time. The temporary Code of Conduct should be superfluous now as 'complete loss of data' should not occur anymore.
Modified paths:
  • /trunk/extensions/Wikidata/WiktionaryZ/DefinedMeaning.php (modified) (history)
  • /trunk/extensions/Wikidata/WiktionaryZ/Transaction.php (modified) (history)
  • /trunk/extensions/Wikidata/WiktionaryZ/Wikidata.php (modified) (history)
  • /trunk/extensions/Wikidata/WiktionaryZ/WiktionaryZ.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/WiktionaryZ/WiktionaryZ.php
@@ -18,7 +18,7 @@
1919 * @package MediaWiki
2020 */
2121 class WiktionaryZ extends DefaultWikidataApplication {
22 - function view() {
 22+ public function view() {
2323 global
2424 $wgOut, $wgTitle;
2525
@@ -33,7 +33,7 @@
3434 # $wgOut->setPageTitleArray($this->mTitle->getTitleArray());
3535 }
3636
37 - function history() {
 37+ public function history() {
3838 global
3939 $wgOut, $wgTitle;
4040
@@ -49,30 +49,18 @@
5050 $wgOut->setPageTitleArray($titleArray);
5151 }
5252
53 - function saveForm() {
 53+ protected function save($referenceTransaction) {
5454 global
55 - $wgTitle, $wgUser, $wgRequest;
 55+ $wgTitle;
5656
57 - $summary = $wgRequest->getText('summary');
58 -
59 - startNewTransaction($wgUser->getID(), wfGetIP(), $summary);
60 -
6157 $spelling = $wgTitle->getText();
62 - getExpressionsEditor($spelling, false)->save(new IdStack("expression"), getExpressionsRecordSet($spelling, new QueryLatestTransactionInformation()));
63 -
64 - Title::touchArray(array($wgTitle));
65 - $now = wfTimestampNow();
66 - RecentChange::notifyEdit($now, $wgTitle, false, $wgUser, $summary,
67 - 0, $now, false, '', 0, 0, 0);
 58+ getExpressionsEditor($spelling, false)->save(new IdStack("expression"), getExpressionsRecordSet($spelling, $referenceTransaction));
6859 }
6960
70 - function edit() {
 61+ public function edit() {
7162 global
72 - $wgOut, $wgTitle, $wgUser, $wgRequest;
 63+ $wgOut, $wgTitle, $wgUser;
7364
74 - if ($wgRequest->getText('save') != '')
75 - $this->saveForm();
76 -
7765 parent::edit();
7866
7967 $spelling = $wgTitle->getText();
@@ -80,13 +68,6 @@
8169 $this->outputEditHeader();
8270 $wgOut->addHTML(getExpressionsEditor($spelling, false)->edit(new IdStack("expression"), getExpressionsRecordSet($spelling, new QueryLatestTransactionInformation())));
8371 $this->outputEditFooter();
84 -
85 - $wgOut->addHTML(DefaultEditor::getExpansionCss());
86 - $wgOut->addHTML("<script language='javascript'><!--\nexpandEditors();\n--></script>");
87 -
88 - $titleArray = $wgTitle->getTitleArray();
89 - $titleArray["actionprefix"] = wfMsg('editing');
90 - $wgOut->setPageTitleArray($titleArray);
9172 }
9273 }
9374
Index: trunk/extensions/Wikidata/WiktionaryZ/Wikidata.php
@@ -1,6 +1,7 @@
22 <?php
33
44 require_once("forms.php");
 5+require_once("Transaction.php");
56
67 interface WikidataApplication {
78 public function view();
@@ -45,10 +46,31 @@
4647 $wgOut->addHTML($this->getLanguageSelector());
4748 }
4849
 50+ protected function save($referenceTransaction) {
 51+ }
 52+
 53+ public function saveWithinTransaction() {
 54+ global
 55+ $wgTitle, $wgUser, $wgRequest;
 56+
 57+ $summary = $wgRequest->getText('summary');
 58+
 59+ startNewTransaction($wgUser->getID(), wfGetIP(), $summary);
 60+ $this->save(new QueryAtTransactionInformation($wgRequest->getInt('transaction')));
 61+
 62+
 63+ Title::touchArray(array($wgTitle));
 64+ $now = wfTimestampNow();
 65+ RecentChange::notifyEdit($now, $wgTitle, false, $wgUser, $summary, 0, $now, false, '', 0, 0, 0);
 66+ }
 67+
4968 public function edit() {
5069 global
51 - $wgOut;
 70+ $wgOut, $wgRequest;
5271
 72+ if ($wgRequest->getText('save') != '')
 73+ $this->saveWithinTransaction();
 74+
5375 $wgOut->addHTML($this->getLanguageSelector());
5476 }
5577
@@ -91,17 +113,26 @@
92114 global
93115 $wgOut;
94116
95 - $wgOut->addHTML('<form method="post" action="">');
 117+ $wgOut->addHTML(
 118+ '<form method="post" action="">' .
 119+ '<input type="hidden" name="transaction" value="'. getLatestTransactionId() .'"/>'
 120+ );
96121 }
97122
98123 protected function outputEditFooter() {
99124 global
100125 $wgOut, $wgTitle;
101126
102 - $wgOut->addHTML('<div class="option-panel">');
103 - $wgOut->addHTML('<table cellpadding="0" cellspacing="0"><tr><th>' . wfMsg('summary') . ': </th><td class="option-field">' . getTextBox("summary") .'</td></tr></table>');
104 - $wgOut->addHTML(getSubmitButton("save", wfMsg('wz_save')));
105 - $wgOut->addHTML('</div>');
 127+ $wgOut->addHTML(
 128+ '<div class="option-panel">'.
 129+ '<table cellpadding="0" cellspacing="0"><tr>' .
 130+ '<th>' . wfMsg('summary') . ': </th>' .
 131+ '<td class="option-field">' . getTextBox("summary") .'</td>' .
 132+ '</tr></table>' .
 133+ getSubmitButton("save", wfMsg('wz_save')).
 134+ '</div>'
 135+ );
 136+
106137 $wgOut->addHTML('</form>');
107138 $wgOut->addHTML(DefaultEditor::getExpansionCss());
108139 $wgOut->addHTML("<script language='javascript'><!--\nexpandEditors();\n--></script>");
Index: trunk/extensions/Wikidata/WiktionaryZ/DefinedMeaning.php
@@ -20,11 +20,8 @@
2121
2222 public function edit() {
2323 global
24 - $wgOut, $wgTitle, $wgRequest;
 24+ $wgOut, $wgTitle;
2525
26 - if ($wgRequest->getText('save') != '')
27 - $this->save();
28 -
2926 parent::edit();
3027
3128 // $definedMeaningId = $wgTitle->getText();
@@ -33,12 +30,9 @@
3431 $this->outputEditHeader();
3532 $wgOut->addHTML(getDefinedMeaningEditor(false)->edit($this->getIdStack($definedMeaningId), getDefinedMeaningRecord($definedMeaningId, new QueryLatestTransactionInformation())));
3633 $this->outputEditFooter();
37 -
38 - $wgOut->addHTML(DefaultEditor::getExpansionCss());
39 - $wgOut->addHTML("<script language='javascript'><!--\nexpandEditors();\n--></script>");
4034 }
4135
42 - function history() {
 36+ public function history() {
4337 global
4438 $wgOut, $wgTitle;
4539
@@ -59,21 +53,13 @@
6054 $wgOut->setPageTitleArray($titleArray);
6155 }
6256
63 - protected function save() {
 57+ protected function save($referenceTransaction) {
6458 global
65 - $wgTitle, $wgUser, $wgRequest;
 59+ $wgTitle;
6660
67 - $summary = $wgRequest->getText('summary');
68 -
69 - startNewTransaction($wgUser->getID(), wfGetIP(), $summary);
70 -
7161 // $definedMeaningId = $wgTitle->getText();
7262 $definedMeaningId = $this->getDefinedMeaningIdFromTitle($wgTitle->getText());
73 - getDefinedMeaningEditor(false)->save($this->getIdStack($definedMeaningId), getDefinedMeaningRecord($definedMeaningId, new QueryLatestTransactionInformation()));
74 -
75 - Title::touchArray(array($wgTitle));
76 - $now = wfTimestampNow();
77 - RecentChange::notifyEdit($now, $wgTitle, false, $wgUser, $summary, 0, $now, false, '', 0, 0, 0);
 63+ getDefinedMeaningEditor(false)->save($this->getIdStack($definedMeaningId), getDefinedMeaningRecord($definedMeaningId, $referenceTransaction));
7864 }
7965
8066 protected function getIdStack($definedMeaningId) {
@@ -95,9 +81,7 @@
9682 $bracketPosition = strrpos($title, "(");
9783 $definedMeaningId = substr($title, $bracketPosition + 1, strlen($title) - $bracketPosition - 2);
9884 return $definedMeaningId;
99 - }
100 -
 85+ }
10186 }
10287
103 -
10488 ?>
Index: trunk/extensions/Wikidata/WiktionaryZ/Transaction.php
@@ -116,6 +116,16 @@
117117 return $updateTransactionId;
118118 }
119119
 120+function getLatestTransactionId() {
 121+ $dbr =& wfGetDB(DB_SLAVE);
 122+ $queryResult = $dbr->query("SELECT max(transaction_id) AS transaction_id FROM transactions");
 123+
 124+ if ($transaction = $dbr->fetchObject($queryResult))
 125+ return $transaction->transaction_id;
 126+ else
 127+ return 0;
 128+}
 129+
120130 function getLatestTransactionRestriction($table) {
121131 return ' '. $table . '.remove_transaction_id IS NULL ';
122132 }