Permalink
Browse files

Updated link updating code to use local item cache rather then langli…

…nks and match SiteLink refactor

Change-Id: I89f218570c18e222824662f8e7ca21a2aac6a085
  • Loading branch information...
1 parent 9cf355c commit e2f1fb38d313e71d1503479c600e6d581648b54f @JeroenDeDauw committed Aug 7, 2012
@@ -113,10 +113,11 @@ public static function onWikibasePollHandle( Change $change ) {
*
* @param \Parser $parser
* @param string $text
+ * @param \StripState $stripState
*
* @return boolean
*/
- public static function onParserBeforeTidy( \Parser &$parser, &$text ) {
+ public static function onParserAfterParse( \Parser &$parser, &$text, \StripState $stripState ) {
$parserOutput = $parser->getOutput();
$localItem = LocalItemsTable::singleton()->selectRow( null, array( 'page_title' => $parser->getTitle()->getDBkey() ) );
@@ -60,7 +60,7 @@
$wgHooks['WikibasePollHandle'][] = '\Wikibase\ClientHooks::onWikibasePollHandle';
$wgHooks['LoadExtensionSchemaUpdates'][] = '\Wikibase\ClientHooks::onSchemaUpdate';
$wgHooks['WikibaseDefaultSettings'][] = '\Wikibase\ClientHooks::onWikibaseDefaultSettings';
-$wgHooks['ParserBeforeTidy'][] = '\Wikibase\LangLinkHandler::onParserBeforeTidy';
+$wgHooks['ParserAfterParse'][] = '\Wikibase\ClientHooks::onParserAfterParse';
$wgHooks['ParserFirstCallInit'][] = '\Wikibase\NoLangLinkHandler::onParserFirstCallInit';
$wgHooks['MagicWordwgVariableIDs'][] = '\Wikibase\NoLangLinkHandler::onMagicWordwgVariableIDs';
$wgHooks['ParserGetVariableValueSwitch'][] = '\Wikibase\NoLangLinkHandler::onParserGetVariableValueSwitch';
@@ -30,12 +30,15 @@ public function handleChange( Change $change ) {
* @var Item $item
*/
$item = $change->getItem();
- $siteLinks = $item->getSiteLinks();
$globalId = 'enwiki'; // TODO
- if ( array_key_exists( $globalId, $siteLinks ) ) {
- $title = \Title::newFromText( $siteLinks[$globalId] );
+ $siteLink = $item->getSiteLink( $globalId );
+
+ // TODO: also detect removal or modification of this link and do corresponding updates
+
+ if ( $siteLink !== null ) {
+ $title = \Title::newFromText( $siteLink->getPage() );
if ( !is_null( $title ) ) {
list( , $subType ) = explode( '-', $change->getType() );
@@ -61,8 +64,6 @@ public function handleChange( Change $change ) {
protected function updateLocalItem( $changeType, Item $item, Title $title ) {
$localItem = LocalItem::newFromItem( $item );
- $localItem->setField( 'page_title', $title->getFullText() );
-
if ( $changeType === 'remove' ) {
$localItem->remove();
}
@@ -43,22 +43,26 @@ public static function newFromItem( Item $item, $loadFromDB = true ) {
$localItem = false;
if ( $loadFromDB ) {
- $localItem = $table->selectRow( null, array( 'item_id' => $item->getId() ) );
+ $localItem = $table->selectRow( array( 'id', 'item_id', 'page_title' ), array( 'item_id' => $item->getId() ) );
}
if ( $localItem === false ) {
$localItem = new static(
$table,
- array( 'item_data' => $item )
+ array(
+ 'item_id' => $item->getId(),
+ )
);
}
- $siteLinks = $item->getSiteLinks();
+ $localItem->setField( 'item_data', $item );
- // TODO: obtain local wiki global id
- // TODO: properly manage this field
- if ( in_array( 'enwiki', SiteLink::getSiteIDs( $siteLinks ) ) ) {
- $localItem->setField( 'page_title', $siteLinks['enwiki'] );
+ $globalId = 'enwiki'; // TODO
+
+ $siteLink = $item->getSiteLink( $globalId );
+
+ if ( $siteLink !== null ) {
+ $localItem->setField( 'page_title', $siteLink->getDBKey() );
}
return $localItem;
@@ -42,7 +42,7 @@ public function getFieldPrefix() {
* @return string
*/
public function getRowClass() {
- return 'LocalItem';
+ return '\Wikibase\LocalItem';
}
/**
@@ -57,7 +57,7 @@ public function getSiteLinks();
*
* @param String $siteId the id of the site to which to get the lin
*
- * @return SiteLink the site link
+ * @return SiteLink|null the corresponding SiteLink object, or null
*/
public function getSiteLink( $siteId );
@@ -96,7 +96,7 @@ public function getSiteLinks() {
}
/**
- * @see Item::getSiteLink()
+ * @see Item::getSiteLink()
*
* @since 0.1
*

0 comments on commit e2f1fb3

Please sign in to comment.