r114298 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114297‎ | r114298 | r114299 >
Date:19:28, 20 March 2012
Author:kipcool
Status:new
Tags:
Comment:
Using only numbers for DefinedMeaning titles
Modified paths:
  • /trunk/extensions/Wikidata/App.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/DefinedMeaning.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/DefinedMeaningModel.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Editor.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/WikiDataGlobals.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Wikidata.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/type.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/App.php
@@ -153,7 +153,6 @@
154154
155155 # FIXME: Should be renamed to prefix with wd rather than wg.
156156 $wgShowClassicPageTitles = false;
157 -$wgDefinedMeaningPageTitlePrefix = '';
158157 $wgExpressionPageTitlePrefix = 'Multiple meanings';
159158
160159 # The site prefix allows us to have multiple sets of customized
Index: trunk/extensions/Wikidata/OmegaWiki/DefinedMeaning.php
@@ -11,52 +11,21 @@
1212 global
1313 $wgOut, $wgTitle, $wgRequest, $wdCurrentContext;
1414
15 - // Split title into defining expression and ID
1615 $titleText = $wgTitle->getText();
17 - $dmInfo = DefinedMeaningModel::splitTitleText( $titleText );
1816
 17+ $dmNumber = (int)$titleText ;
 18+
1919 // Title doesn't have an ID in it (or ID 0)
20 - if ( is_null( $dmInfo ) || !$dmInfo["id"] ) {
 20+ if ( !$dmNumber ) {
2121 $wgOut->showErrorPage( 'errorpagetitle', 'ow_dm_badtitle' );
2222 return false;
2323 }
2424 parent::view();
25 - $definedMeaningModel = new DefinedMeaningModel( $dmInfo["id"], $this->viewInformation );
 25+ $definedMeaningModel = new DefinedMeaningModel( $dmNumber, $this->viewInformation );
2626 $this->definedMeaningModel = $definedMeaningModel; # TODO if I wasn't so sleepy I'd make this consistent
2727
28 - $copyTo = $wgRequest->getText( 'CopyTo' );
29 - if ( $copyTo ) {
30 - $definedMeaningModel->copyTo( $copyTo );
31 - }
32 -
33 - if ( !empty( $dmInfo["expression"] ) ) {
34 - $definedMeaningModel->setDefiningExpression( $dmInfo["expression"] );
35 - }
36 -
37 - // Search for this DM in all data-sets, beginning with the current one.
38 - // Switch dataset context if found elsewhere.
 28+ // check that the constructed DM actually exists in the database
3929 $match = $definedMeaningModel->checkExistence( true, true );
40 -
41 - // The defining expression is likely incorrect for some reason. Let's just
42 - // try looking up the number.
43 - if ( is_null( $match ) && !empty( $dmInfo["expression"] ) ) {
44 - $definedMeaningModel->setDefiningExpression( null );
45 - $dmInfo["expression"] = null;
46 - $match = $definedMeaningModel->checkExistence( true, true );
47 - }
48 -
49 - // The defining expression is either bad or missing. Let's redirect
50 - // to the correct URL.
51 - if ( empty( $dmInfo["expression"] ) && !is_null( $match ) ) {
52 - $definedMeaningModel->loadRecord();
53 - $title = Title::newFromText( $definedMeaningModel->getWikiTitle() );
54 - $url = $title->getFullURL();
55 - $wgOut->disable();
56 - header( "Location: $url" );
57 - return false;
58 - }
59 -
60 - // Bad defining expression AND bad ID! :-(
6130 if ( is_null( $match ) ) {
6231 $wgOut->showErrorPage( 'errorpagetitle', 'ow_dm_missing' );
6332 return false;
@@ -76,24 +45,40 @@
7746 $this->outputViewHeader();
7847 // concept panel is annoying and useless
7948 // $wgOut->addHTML( $this->getConceptPanel() );
 49+ $expressionTranslated = definedMeaningExpression( $this->definedMeaningModel->getId() ) ;
 50+ $wgOut->setPageTitle( $wgTitle->getFullText() . " - $expressionTranslated" ) ;
 51+
8052 $editor = getDefinedMeaningEditor( $this->viewInformation );
8153 $idStack = $this->getIdStack( $definedMeaningModel->getId() );
8254 $html = $editor->view( $idStack, $definedMeaningModel->getRecord() );
8355 $wgOut->addHTML( $html );
8456 $this->outputViewFooter();
8557 }
86 -
 58+
8759 public function edit() {
8860 global
8961 $wgOut, $wgTitle;
9062
9163 if ( !parent::edit() ) return false;
9264
93 - $definedMeaningId = $this->getDefinedMeaningIdFromTitle( $wgTitle->getText() );
 65+ $definedMeaningId = (int)$wgTitle->getText();
9466
 67+ // Title doesn't have an ID in it (or ID 0)
 68+ if ( !$definedMeaningId ) {
 69+ $wgOut->showErrorPage( 'errorpagetitle', 'ow_dm_badtitle' );
 70+ return false;
 71+ }
 72+
9573 $this->outputEditHeader();
9674 $dmModel = new DefinedMeaningModel( $definedMeaningId, $this->viewInformation );
97 -
 75+
 76+ // check that the constructed DM actually exists in the database
 77+ $match = $dmModel->checkExistence( true, true );
 78+ if ( is_null( $match ) ) {
 79+ $wgOut->showErrorPage( 'errorpagetitle', 'ow_dm_missing' );
 80+ return false;
 81+ }
 82+
9883 if ( is_null( $dmModel->getRecord() ) ) {
9984 $wgOut->addHTML( wfMsgSc( "db_consistency__not_found" ) . " ID:$definedMeaningId" );
10085 return;
@@ -112,10 +97,24 @@
11398 global
11499 $wgOut, $wgTitle ;
115100
 101+ $definedMeaningId = (int)$wgTitle->getText();
 102+ // Title doesn't have an ID in it (or ID 0)
 103+ if ( !$definedMeaningId ) {
 104+ $wgOut->showErrorPage( 'errorpagetitle', 'ow_dm_badtitle' );
 105+ return false;
 106+ }
 107+
116108 parent::history();
117109
118 - $definedMeaningId = $this->getDefinedMeaningIdFromTitle( $wgTitle->getText() );
119110 $dmModel = new DefinedMeaningModel( $definedMeaningId, $this->viewInformation );
 111+
 112+ // check that the constructed DM actually exists in the database
 113+ $match = $dmModel->checkExistence( true, true );
 114+ if ( is_null( $match ) ) {
 115+ $wgOut->showErrorPage( 'errorpagetitle', 'ow_dm_missing' );
 116+ return false;
 117+ }
 118+
120119 $wgOut->addHTML(
121120 getDefinedMeaningEditor( $this->viewInformation )->view(
122121 new IdStack( WD_DEFINED_MEANING ),
@@ -132,10 +131,15 @@
133132 $wgTitle;
134133
135134 parent::save( $referenceQueryTransactionInformation );
136 - $definedMeaningId = $this->getDefinedMeaningIdFromTitle( $wgTitle->getText() );
137 -
 135+
 136+ $definedMeaningId = (int)$wgTitle->getText();
 137+ if ( !$definedMeaningId ) {
 138+ // Title doesn't have an ID in it (or ID 0)
 139+ $wgOut->showErrorPage( 'errorpagetitle', 'ow_dm_badtitle' );
 140+ return false;
 141+ }
 142+
138143 $dmModel = new DefinedMeaningModel( $definedMeaningId, $this->viewInformation );
139 - $definedMeaningId = $this->getDefinedMeaningIdFromTitle( $wgTitle->getText() );
140144
141145 getDefinedMeaningEditor( $this->viewInformation )->save(
142146 $this->getIdStack( $definedMeaningId ),
@@ -157,33 +161,7 @@
158162
159163 return $idStack;
160164 }
161 -
162 - /** @deprecated, use DefinedMeaningData.setTitle instead */
163 - protected function getDefinedMeaningIdFromTitle( $title ) {
164 - // get id from title: DefinedMeaning:expression (id)
165 - $bracketPosition = strrpos( $title, "(" );
166 - $definedMeaningId = substr( $title, $bracketPosition + 1, strlen( $title ) - $bracketPosition - 2 );
167 - return $definedMeaningId;
168 - }
169 -
170 - public function getTitle() {
171 - global
172 - $wgTitle, $wgDefinedMeaningPageTitlePrefix;
173 -
174 - if ( $wgDefinedMeaningPageTitlePrefix != "" )
175 - $prefix = $wgDefinedMeaningPageTitlePrefix . ": ";
176 - else
177 - $prefix = "";
178 -
179 - return $prefix . definedMeaningExpression( $this->getDefinedMeaningIdFromTitle( $wgTitle->getText() ) );
180 - }
181165
182 - public function getDefinedMeaningId() {
183 - global
184 - $wgTitle;
185 - return $this->getDefinedMeaningIdFromTitle( $wgTitle->getText() );
186 - }
187 -
188166 /**
189167 * Creates sidebar HTML for indicating concepts which exist
190168 * in multiple datasets, and providing a link to add new
Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataGlobals.php
@@ -65,13 +65,8 @@
6666
6767 // Page titles
6868
69 -global
70 - $wgDefinedMeaningPageTitlePrefix,
71 - // $wgExpressionPageTitlePrefix;
72 - $wgUseExpressionPageTitlePrefix;
73 -
74 -$wgDefinedMeaningPageTitlePrefix = "";
75 -// $wgExpressionPageTitlePrefix = "Multiple meanings"; # Now it's localizable
 69+global $wgUseExpressionPageTitlePrefix;
 70+
7671 $wgUseExpressionPageTitlePrefix = true; # malafaya: Use the expression prefix "Multiple meanings:" from message ow_Multiple_meanings
7772
7873 // Search page
Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php
@@ -795,8 +795,7 @@
796796
797797 // wfDebug( "addDefinedMeaning(): after $definedMeaningId has been inserted in the database" );
798798
799 - $expression = getExpression( $definingExpressionId );
800 - $pageId = createPage( NS_DEFINEDMEANING, getPageTitle( "$expression->spelling ($definedMeaningId)" ) );
 799+ $pageId = createPage( NS_DEFINEDMEANING, getPageTitle( $definedMeaningId ) );
801800 createInitialRevisionForPage( $pageId, 'Created by adding defined meaning' );
802801
803802 return $definedMeaningId;
Index: trunk/extensions/Wikidata/OmegaWiki/Wikidata.php
@@ -62,11 +62,12 @@
6363
6464 $title = $wgTitle->getPrefixedText();
6565
66 - if ( !$this->showClassicPageTitles )
 66+ if ( !$this->showClassicPageTitles ) {
6767 $title = $this->getTitle();
 68+ }
6869
6970 $wgOut->setPageTitle( $title );
70 -
 71+
7172 $this->queryTransactionInformation = new QueryLatestTransactionInformation();
7273
7374 $viewInformation = new ViewInformation();
Index: trunk/extensions/Wikidata/OmegaWiki/DefinedMeaningModel.php
@@ -35,6 +35,7 @@
3636
3737 if ( !$definedMeaningId ) throw new Exception( "DM needs at least a DMID!" );
3838 $this->setId( $definedMeaningId );
 39+
3940 if ( is_null( $viewInformation ) ) {
4041 $viewInformation = new ViewInformation();
4142 $viewInformation->queryTransactionInformation = new QueryLatestTransactionInformation();
@@ -119,19 +120,7 @@
120121 if ( !$dmRow || !$dmRow->defined_meaning_id ) {
121122 return null;
122123 }
123 - if ( is_null( $definingExpression ) ) {
124 - return $dc;
125 - } else {
126 - $expid = (int)$dmRow->expression_id;
127 - $storedExpression = getExpression( $expid, $dc );
128 - if ( is_null( $storedExpression ) ) return null;
129 - if ( $storedExpression->spelling != $definingExpression ) {
130 - // Defining expression does not match, but check was requested!
131 - return null;
132 - } else {
133 - return $dc;
134 - }
135 - }
 124+ return $dc;
136125 }
137126 /**
138127 * Load the associated record object.
@@ -399,14 +388,13 @@
400389 */
401390 public function getTitleObject() {
402391 if ( $this->titleObject == null ) {
403 - $definingExpression = $this->getDefiningExpression();
404392 $id = $this->getId();
405393
406 - if ( is_null( $definingExpression ) or is_null( $id ) )
 394+ if ( is_null( $id ) ) {
407395 return null;
 396+ }
408397
409 - $definingExpressionAsTitle = str_replace( " ", "_", $definingExpression );
410 - $text = "DefinedMeaning:" . $definingExpressionAsTitle . "_($id)";
 398+ $text = "DefinedMeaning:" . $id;
411399 $titleObject = Title::newFromText( $text );
412400 $this->titleObject = $titleObject;
413401 }
@@ -434,33 +422,6 @@
435423 }
436424
437425 /**
438 - *
439 - * Splits title of the form "Abc (123)" into text and number
440 - * components.
441 - *
442 - * @param String the title to analyze
443 - * @return Array of the two components or null.
444 - *
445 - */
446 - public static function splitTitleText( $titleText ) {
447 - $bracketPosition = strrpos( $titleText, "(" );
448 - if ( $bracketPosition === false )
449 - return null; # Defined Meaning ID is missing from title string
450 - $rv = array();
451 - if ( $bracketPosition > 0 ) {
452 - $definingExpression = substr( $titleText, 0, $bracketPosition - 1 );
453 - $definingExpression = str_replace( "_", " ", $definingExpression );
454 - } else {
455 - $definingExpression = null;
456 - }
457 - $definedMeaningId = substr( $titleText, $bracketPosition + 1, strlen( $titleText ) - $bracketPosition - 2 );
458 -
459 - $rv["expression"] = $definingExpression;
460 - $rv["id"] = (int)$definedMeaningId;
461 - return $rv;
462 - }
463 -
464 - /**
465426 * @return full text representation of title
466427 */
467428 public function getTitleText() {
@@ -488,12 +449,9 @@
489450 }
490451
491452 public function getWikiTitle() {
492 - $dmEx = $this->getDefiningExpression();
493453 $dmId = $this->getId();
494 - $dmTitle = "DefinedMeaning:$dmEx ($dmId)";
495 - $dmTitle = str_replace( " ", "_", $dmTitle );
 454+ $dmTitle = "DefinedMeaning:$dmId";
496455 return $dmTitle;
497 -
498456 }
499457
500458 public function setDefiningExpression( $definingExpression ) {
Index: trunk/extensions/Wikidata/OmegaWiki/type.php
@@ -60,12 +60,8 @@
6161 return $title->getLocalURL( $query ) ;
6262 }
6363
64 -function definedMeaningReferenceAsURL( $definedMeaningId, $definingExpression ) {
65 - return pageAsURL( "DefinedMeaning", "$definingExpression ($definedMeaningId)" );
66 -}
67 -
6864 function definedMeaningIdAsURL( $definedMeaningId ) {
69 - return definedMeaningReferenceAsURL( $definedMeaningId, definingExpression( $definedMeaningId ) );
 65+ return pageAsURL( "DefinedMeaning", "$definedMeaningId" );
7066 }
7167
7268 function createLink( $url, $text ) {
@@ -77,7 +73,7 @@
7874 }
7975
8076 function definedMeaningReferenceAsLink( $definedMeaningId, $definingExpression, $label ) {
81 - return createLink( definedMeaningReferenceAsURL( $definedMeaningId, $definingExpression ), $label );
 77+ return createLink( definedMeaningIdAsURL( $definedMeaningId ), $label );
8278 }
8379
8480 function languageIdAsText( $languageId ) {
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php
@@ -1248,7 +1248,7 @@
12491249 $isMetaDescSet = 1 ;
12501250 }
12511251
1252 - $DMPageName = definingExpression( $value ) . " (" . $value . ")" ;
 1252+ $DMPageName = $value ;
12531253 $DMTitle = Title::makeTitle( NS_DEFINEDMEANING , $DMPageName );
12541254 $editURL = $DMTitle->getLocalURL( 'action=edit' ) ;
12551255 $editLink = '<div style="float:right; font-size:60%;"><sup>['

Status & tagging log