https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114298
Revision: 114298
Author: kipcool
Date: 2012-03-20 19:28:32 +0000 (Tue, 20 Mar 2012)
Log Message:
-----------
Using only numbers for DefinedMeaning titles
Modified Paths:
--------------
trunk/extensions/Wikidata/App.php
trunk/extensions/Wikidata/OmegaWiki/DefinedMeaning.php
trunk/extensions/Wikidata/OmegaWiki/DefinedMeaningModel.php
trunk/extensions/Wikidata/OmegaWiki/Editor.php
trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php
trunk/extensions/Wikidata/OmegaWiki/WikiDataGlobals.php
trunk/extensions/Wikidata/OmegaWiki/Wikidata.php
trunk/extensions/Wikidata/OmegaWiki/type.php
Modified: trunk/extensions/Wikidata/App.php
===================================================================
--- trunk/extensions/Wikidata/App.php 2012-03-20 19:23:19 UTC (rev 114297)
+++ trunk/extensions/Wikidata/App.php 2012-03-20 19:28:32 UTC (rev 114298)
@@ -153,7 +153,6 @@
# FIXME: Should be renamed to prefix with wd rather than wg.
$wgShowClassicPageTitles = false;
-$wgDefinedMeaningPageTitlePrefix = '';
$wgExpressionPageTitlePrefix = 'Multiple meanings';
# The site prefix allows us to have multiple sets of customized
Modified: trunk/extensions/Wikidata/OmegaWiki/DefinedMeaning.php
===================================================================
--- trunk/extensions/Wikidata/OmegaWiki/DefinedMeaning.php 2012-03-20
19:23:19 UTC (rev 114297)
+++ trunk/extensions/Wikidata/OmegaWiki/DefinedMeaning.php 2012-03-20
19:28:32 UTC (rev 114298)
@@ -11,52 +11,21 @@
global
$wgOut, $wgTitle, $wgRequest, $wdCurrentContext;
- // Split title into defining expression and ID
$titleText = $wgTitle->getText();
- $dmInfo = DefinedMeaningModel::splitTitleText( $titleText );
+ $dmNumber = (int)$titleText ;
+
// Title doesn't have an ID in it (or ID 0)
- if ( is_null( $dmInfo ) || !$dmInfo["id"] ) {
+ if ( !$dmNumber ) {
$wgOut->showErrorPage( 'errorpagetitle',
'ow_dm_badtitle' );
return false;
}
parent::view();
- $definedMeaningModel = new DefinedMeaningModel( $dmInfo["id"],
$this->viewInformation );
+ $definedMeaningModel = new DefinedMeaningModel( $dmNumber,
$this->viewInformation );
$this->definedMeaningModel = $definedMeaningModel; # TODO if I
wasn't so sleepy I'd make this consistent
- $copyTo = $wgRequest->getText( 'CopyTo' );
- if ( $copyTo ) {
- $definedMeaningModel->copyTo( $copyTo );
- }
-
- if ( !empty( $dmInfo["expression"] ) ) {
- $definedMeaningModel->setDefiningExpression(
$dmInfo["expression"] );
- }
-
- // Search for this DM in all data-sets, beginning with the
current one.
- // Switch dataset context if found elsewhere.
+ // check that the constructed DM actually exists in the database
$match = $definedMeaningModel->checkExistence( true, true );
-
- // The defining expression is likely incorrect for some reason.
Let's just
- // try looking up the number.
- if ( is_null( $match ) && !empty( $dmInfo["expression"] ) ) {
- $definedMeaningModel->setDefiningExpression( null );
- $dmInfo["expression"] = null;
- $match = $definedMeaningModel->checkExistence( true,
true );
- }
-
- // The defining expression is either bad or missing. Let's
redirect
- // to the correct URL.
- if ( empty( $dmInfo["expression"] ) && !is_null( $match ) ) {
- $definedMeaningModel->loadRecord();
- $title = Title::newFromText(
$definedMeaningModel->getWikiTitle() );
- $url = $title->getFullURL();
- $wgOut->disable();
- header( "Location: $url" );
- return false;
- }
-
- // Bad defining expression AND bad ID! :-(
if ( is_null( $match ) ) {
$wgOut->showErrorPage( 'errorpagetitle',
'ow_dm_missing' );
return false;
@@ -76,24 +45,40 @@
$this->outputViewHeader();
// concept panel is annoying and useless
// $wgOut->addHTML( $this->getConceptPanel() );
+ $expressionTranslated = definedMeaningExpression(
$this->definedMeaningModel->getId() ) ;
+ $wgOut->setPageTitle( $wgTitle->getFullText() . " -
$expressionTranslated" ) ;
+
$editor = getDefinedMeaningEditor( $this->viewInformation );
$idStack = $this->getIdStack( $definedMeaningModel->getId() );
$html = $editor->view( $idStack,
$definedMeaningModel->getRecord() );
$wgOut->addHTML( $html );
$this->outputViewFooter();
}
-
+
public function edit() {
global
$wgOut, $wgTitle;
if ( !parent::edit() ) return false;
- $definedMeaningId = $this->getDefinedMeaningIdFromTitle(
$wgTitle->getText() );
+ $definedMeaningId = (int)$wgTitle->getText();
+ // Title doesn't have an ID in it (or ID 0)
+ if ( !$definedMeaningId ) {
+ $wgOut->showErrorPage( 'errorpagetitle',
'ow_dm_badtitle' );
+ return false;
+ }
+
$this->outputEditHeader();
$dmModel = new DefinedMeaningModel( $definedMeaningId,
$this->viewInformation );
-
+
+ // check that the constructed DM actually exists in the database
+ $match = $dmModel->checkExistence( true, true );
+ if ( is_null( $match ) ) {
+ $wgOut->showErrorPage( 'errorpagetitle',
'ow_dm_missing' );
+ return false;
+ }
+
if ( is_null( $dmModel->getRecord() ) ) {
$wgOut->addHTML( wfMsgSc( "db_consistency__not_found" )
. " ID:$definedMeaningId" );
return;
@@ -112,10 +97,24 @@
global
$wgOut, $wgTitle ;
+ $definedMeaningId = (int)$wgTitle->getText();
+ // Title doesn't have an ID in it (or ID 0)
+ if ( !$definedMeaningId ) {
+ $wgOut->showErrorPage( 'errorpagetitle',
'ow_dm_badtitle' );
+ return false;
+ }
+
parent::history();
- $definedMeaningId = $this->getDefinedMeaningIdFromTitle(
$wgTitle->getText() );
$dmModel = new DefinedMeaningModel( $definedMeaningId,
$this->viewInformation );
+
+ // check that the constructed DM actually exists in the database
+ $match = $dmModel->checkExistence( true, true );
+ if ( is_null( $match ) ) {
+ $wgOut->showErrorPage( 'errorpagetitle',
'ow_dm_missing' );
+ return false;
+ }
+
$wgOut->addHTML(
getDefinedMeaningEditor( $this->viewInformation )->view(
new IdStack( WD_DEFINED_MEANING ),
@@ -132,10 +131,15 @@
$wgTitle;
parent::save( $referenceQueryTransactionInformation );
- $definedMeaningId = $this->getDefinedMeaningIdFromTitle(
$wgTitle->getText() );
-
+
+ $definedMeaningId = (int)$wgTitle->getText();
+ if ( !$definedMeaningId ) {
+ // Title doesn't have an ID in it (or ID 0)
+ $wgOut->showErrorPage( 'errorpagetitle',
'ow_dm_badtitle' );
+ return false;
+ }
+
$dmModel = new DefinedMeaningModel( $definedMeaningId,
$this->viewInformation );
- $definedMeaningId = $this->getDefinedMeaningIdFromTitle(
$wgTitle->getText() );
getDefinedMeaningEditor( $this->viewInformation )->save(
$this->getIdStack( $definedMeaningId ),
@@ -157,33 +161,7 @@
return $idStack;
}
-
- /** @deprecated, use DefinedMeaningData.setTitle instead */
- protected function getDefinedMeaningIdFromTitle( $title ) {
- // get id from title: DefinedMeaning:expression (id)
- $bracketPosition = strrpos( $title, "(" );
- $definedMeaningId = substr( $title, $bracketPosition + 1,
strlen( $title ) - $bracketPosition - 2 );
- return $definedMeaningId;
- }
-
- public function getTitle() {
- global
- $wgTitle, $wgDefinedMeaningPageTitlePrefix;
-
- if ( $wgDefinedMeaningPageTitlePrefix != "" )
- $prefix = $wgDefinedMeaningPageTitlePrefix . ": ";
- else
- $prefix = "";
-
- return $prefix . definedMeaningExpression(
$this->getDefinedMeaningIdFromTitle( $wgTitle->getText() ) );
- }
- public function getDefinedMeaningId() {
- global
- $wgTitle;
- return $this->getDefinedMeaningIdFromTitle( $wgTitle->getText()
);
- }
-
/**
* Creates sidebar HTML for indicating concepts which exist
* in multiple datasets, and providing a link to add new
Modified: trunk/extensions/Wikidata/OmegaWiki/DefinedMeaningModel.php
===================================================================
--- trunk/extensions/Wikidata/OmegaWiki/DefinedMeaningModel.php 2012-03-20
19:23:19 UTC (rev 114297)
+++ trunk/extensions/Wikidata/OmegaWiki/DefinedMeaningModel.php 2012-03-20
19:28:32 UTC (rev 114298)
@@ -35,6 +35,7 @@
if ( !$definedMeaningId ) throw new Exception( "DM needs at
least a DMID!" );
$this->setId( $definedMeaningId );
+
if ( is_null( $viewInformation ) ) {
$viewInformation = new ViewInformation();
$viewInformation->queryTransactionInformation = new
QueryLatestTransactionInformation();
@@ -119,19 +120,7 @@
if ( !$dmRow || !$dmRow->defined_meaning_id ) {
return null;
}
- if ( is_null( $definingExpression ) ) {
- return $dc;
- } else {
- $expid = (int)$dmRow->expression_id;
- $storedExpression = getExpression( $expid, $dc );
- if ( is_null( $storedExpression ) ) return null;
- if ( $storedExpression->spelling != $definingExpression
) {
- // Defining expression does not match, but
check was requested!
- return null;
- } else {
- return $dc;
- }
- }
+ return $dc;
}
/**
* Load the associated record object.
@@ -399,14 +388,13 @@
*/
public function getTitleObject() {
if ( $this->titleObject == null ) {
- $definingExpression = $this->getDefiningExpression();
$id = $this->getId();
- if ( is_null( $definingExpression ) or is_null( $id ) )
+ if ( is_null( $id ) ) {
return null;
+ }
- $definingExpressionAsTitle = str_replace( " ", "_",
$definingExpression );
- $text = "DefinedMeaning:" . $definingExpressionAsTitle
. "_($id)";
+ $text = "DefinedMeaning:" . $id;
$titleObject = Title::newFromText( $text );
$this->titleObject = $titleObject;
}
@@ -434,33 +422,6 @@
}
/**
- *
- * Splits title of the form "Abc (123)" into text and number
- * components.
- *
- * @param String the title to analyze
- * @return Array of the two components or null.
- *
- */
- public static function splitTitleText( $titleText ) {
- $bracketPosition = strrpos( $titleText, "(" );
- if ( $bracketPosition === false )
- return null; # Defined Meaning ID is missing from title
string
- $rv = array();
- if ( $bracketPosition > 0 ) {
- $definingExpression = substr( $titleText, 0,
$bracketPosition - 1 );
- $definingExpression = str_replace( "_", " ",
$definingExpression );
- } else {
- $definingExpression = null;
- }
- $definedMeaningId = substr( $titleText, $bracketPosition + 1,
strlen( $titleText ) - $bracketPosition - 2 );
-
- $rv["expression"] = $definingExpression;
- $rv["id"] = (int)$definedMeaningId;
- return $rv;
- }
-
- /**
* @return full text representation of title
*/
public function getTitleText() {
@@ -488,12 +449,9 @@
}
public function getWikiTitle() {
- $dmEx = $this->getDefiningExpression();
$dmId = $this->getId();
- $dmTitle = "DefinedMeaning:$dmEx ($dmId)";
- $dmTitle = str_replace( " ", "_", $dmTitle );
+ $dmTitle = "DefinedMeaning:$dmId";
return $dmTitle;
-
}
public function setDefiningExpression( $definingExpression ) {
Modified: trunk/extensions/Wikidata/OmegaWiki/Editor.php
===================================================================
--- trunk/extensions/Wikidata/OmegaWiki/Editor.php 2012-03-20 19:23:19 UTC
(rev 114297)
+++ trunk/extensions/Wikidata/OmegaWiki/Editor.php 2012-03-20 19:28:32 UTC
(rev 114298)
@@ -1248,7 +1248,7 @@
$isMetaDescSet = 1 ;
}
- $DMPageName = definingExpression( $value ) . " (" . $value .
")" ;
+ $DMPageName = $value ;
$DMTitle = Title::makeTitle( NS_DEFINEDMEANING , $DMPageName );
$editURL = $DMTitle->getLocalURL( 'action=edit' ) ;
$editLink = '<div style="float:right; font-size:60%;"><sup>['
Modified: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php
===================================================================
--- trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php 2012-03-20 19:23:19 UTC
(rev 114297)
+++ trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php 2012-03-20 19:28:32 UTC
(rev 114298)
@@ -795,8 +795,7 @@
// wfDebug( "addDefinedMeaning(): after $definedMeaningId has been
inserted in the database" );
- $expression = getExpression( $definingExpressionId );
- $pageId = createPage( NS_DEFINEDMEANING, getPageTitle(
"$expression->spelling ($definedMeaningId)" ) );
+ $pageId = createPage( NS_DEFINEDMEANING, getPageTitle(
$definedMeaningId ) );
createInitialRevisionForPage( $pageId, 'Created by adding defined
meaning' );
return $definedMeaningId;
Modified: trunk/extensions/Wikidata/OmegaWiki/WikiDataGlobals.php
===================================================================
--- trunk/extensions/Wikidata/OmegaWiki/WikiDataGlobals.php 2012-03-20
19:23:19 UTC (rev 114297)
+++ trunk/extensions/Wikidata/OmegaWiki/WikiDataGlobals.php 2012-03-20
19:28:32 UTC (rev 114298)
@@ -65,13 +65,8 @@
// Page titles
-global
- $wgDefinedMeaningPageTitlePrefix,
- // $wgExpressionPageTitlePrefix;
- $wgUseExpressionPageTitlePrefix;
-
-$wgDefinedMeaningPageTitlePrefix = "";
-// $wgExpressionPageTitlePrefix = "Multiple meanings"; # Now it's localizable
+global $wgUseExpressionPageTitlePrefix;
+
$wgUseExpressionPageTitlePrefix = true; # malafaya: Use the expression
prefix "Multiple meanings:" from message ow_Multiple_meanings
// Search page
Modified: trunk/extensions/Wikidata/OmegaWiki/Wikidata.php
===================================================================
--- trunk/extensions/Wikidata/OmegaWiki/Wikidata.php 2012-03-20 19:23:19 UTC
(rev 114297)
+++ trunk/extensions/Wikidata/OmegaWiki/Wikidata.php 2012-03-20 19:28:32 UTC
(rev 114298)
@@ -62,11 +62,12 @@
$title = $wgTitle->getPrefixedText();
- if ( !$this->showClassicPageTitles )
+ if ( !$this->showClassicPageTitles ) {
$title = $this->getTitle();
+ }
$wgOut->setPageTitle( $title );
-
+
$this->queryTransactionInformation = new
QueryLatestTransactionInformation();
$viewInformation = new ViewInformation();
Modified: trunk/extensions/Wikidata/OmegaWiki/type.php
===================================================================
--- trunk/extensions/Wikidata/OmegaWiki/type.php 2012-03-20 19:23:19 UTC
(rev 114297)
+++ trunk/extensions/Wikidata/OmegaWiki/type.php 2012-03-20 19:28:32 UTC
(rev 114298)
@@ -60,12 +60,8 @@
return $title->getLocalURL( $query ) ;
}
-function definedMeaningReferenceAsURL( $definedMeaningId, $definingExpression
) {
- return pageAsURL( "DefinedMeaning", "$definingExpression
($definedMeaningId)" );
-}
-
function definedMeaningIdAsURL( $definedMeaningId ) {
- return definedMeaningReferenceAsURL( $definedMeaningId,
definingExpression( $definedMeaningId ) );
+ return pageAsURL( "DefinedMeaning", "$definedMeaningId" );
}
function createLink( $url, $text ) {
@@ -77,7 +73,7 @@
}
function definedMeaningReferenceAsLink( $definedMeaningId,
$definingExpression, $label ) {
- return createLink( definedMeaningReferenceAsURL( $definedMeaningId,
$definingExpression ), $label );
+ return createLink( definedMeaningIdAsURL( $definedMeaningId ), $label );
}
function languageIdAsText( $languageId ) {
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs