Index: trunk/extensions/Wikidata/SpecialLanguages.php |
— | — | @@ -13,14 +13,13 @@ |
14 | 14 | $wgAvailableRights[] = 'addlanguage'; |
15 | 15 | $wgGroupPermissions['bureaucrat']['addlanguage'] = true; |
16 | 16 | |
17 | | -$wgExtensionFunctions[] = 'wfSpecialManageLanguages'; |
18 | 17 | $wgExtensionCredits['specialpage'][] = array( |
19 | 18 | 'name' => 'Language manager', |
20 | 19 | 'author' => 'Erik Moeller', |
21 | 20 | 'descmsg' => 'langman-desc', |
22 | 21 | ); |
23 | 22 | |
24 | | -$wgSpecialPages[] = 'SpecialLanguages'; |
| 23 | +$wgSpecialPages['Languages'] = 'SpecialLanguages'; |
25 | 24 | |
26 | 25 | class SpecialLanguages extends SpecialPage { |
27 | 26 | function SpecialLanguages() { |
Index: trunk/extensions/Wikidata/Wikidata.hooks.php |
— | — | @@ -0,0 +1,142 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class WikidataHooks { |
| 5 | + |
| 6 | + public static function onBeforePageDisplay( &$out, &$skin ) { |
| 7 | + global $wgLang, $wgScriptPath; |
| 8 | + $out->addScript( "<script type='text/javascript' src='$wgScriptPath/extensions/Wikidata/OmegaWiki/suggest.js'></script>" ); |
| 9 | + $out->addScript( "<script type='text/javascript' src='$wgScriptPath/extensions/Wikidata/OmegaWiki/omegawiki-ajax.js'></script>" ); |
| 10 | + |
| 11 | + if ( $wgLang->isRTL() ) { |
| 12 | + $rtl = '-rtl'; |
| 13 | + |
| 14 | + # FIXME: Why are we including Gadget CSS here, this is Wikidata? |
| 15 | + $wgOut->addHTML( '<style type="text/css">/*<![CDATA[*/ @import "/index.php?title=MediaWiki:Gadget-rtl.css&action=raw&ctype=text/css"; /*]]>*/</style>' ); |
| 16 | + } else { |
| 17 | + $rtl = ''; |
| 18 | + } |
| 19 | + |
| 20 | + $out->addLink( array( 'rel' => 'stylesheet', 'type' => 'text/css', 'media' => 'screen', 'href' => "$wgScriptPath/extensions/Wikidata/OmegaWiki/suggest$rtl.css" ) ); |
| 21 | + $out->addLink( array( 'rel' => 'stylesheet', 'type' => 'text/css', 'media' => 'screen', 'href' => "$wgScriptPath/extensions/Wikidata/OmegaWiki/tables$rtl.css" ) ); |
| 22 | + return true; |
| 23 | + } |
| 24 | + |
| 25 | + private static function isWikidataNs( $title ) { |
| 26 | + global $wdHandlerClasses; |
| 27 | + return array_key_exists( $title->getNamespace(), $wdHandlerClasses ); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Purpose: Add custom tabs |
| 32 | + * |
| 33 | + * When editing in read-only data-set, if you have the copy permission, you can |
| 34 | + * make a copy into the designated community dataset and edit the data there. |
| 35 | + * This is accessible through an 'edit copy' tab which is added below. |
| 36 | + * |
| 37 | + * @param $skin Skin as passed by MW |
| 38 | + * @param $tabs as passed by MW |
| 39 | + */ |
| 40 | + public static function onSkinTemplateTabs( $skin, $content_actions ) { |
| 41 | + global $wgUser, $wgCommunity_dc, $wdShowEditCopy, $wdHandlerClasses; |
| 42 | + |
| 43 | + $title = $skin->getTitle(); |
| 44 | + |
| 45 | + if ( !self::isWikidataNs( $title ) ) { |
| 46 | + return true; |
| 47 | + } |
| 48 | + |
| 49 | + $ns = $title->getNamespace(); |
| 50 | + $editChanged = false; |
| 51 | + $dc = wdGetDataSetContext(); |
| 52 | + |
| 53 | + if ( $wdHandlerClasses[ $ns ] == 'DefinedMeaning' ) { |
| 54 | + |
| 55 | + # Hackishly determine which DMID we're on by looking at the page title component |
| 56 | + $tt = $title->getText(); |
| 57 | + $rpos1 = strrpos( $tt, '(' ); |
| 58 | + $rpos2 = strrpos( $tt, ')' ); |
| 59 | + $dmid = ( $rpos1 && $rpos2 ) ? substr( $tt, $rpos1 + 1, $rpos2 - $rpos1 - 1 ) : 0; |
| 60 | + if ( $dmid ) { |
| 61 | + $copyTitle = SpecialPage::getTitleFor( 'Copy' ); |
| 62 | + if ( $dc != $wgCommunity_dc && $wdShowEditCopy ) { |
| 63 | + $editChanged = true; |
| 64 | + $content_actions['edit'] = array( |
| 65 | + 'class' => false, |
| 66 | + 'text' => wfMsg( 'ow_nstab_edit_copy' ), |
| 67 | + 'href' => $copyTitle->getLocalUrl( "action=copy&dmid=$dmid&dc1=$dc&dc2=$wgCommunity_dc" ) |
| 68 | + ); |
| 69 | + } |
| 70 | + $content_actions['nstab-definedmeaning'] = array( |
| 71 | + 'class' => 'selected', |
| 72 | + 'text' => wfMsg( 'ow_nstab_definedmeaning' ), |
| 73 | + 'href' => $title->getLocalUrl( "dataset=$dc" ) |
| 74 | + ); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + // Prevent move tab being shown. |
| 79 | + unset( $content_actions['move'] ); |
| 80 | + |
| 81 | + // Add context dataset (old hooks 'GetEditLinkTrail' and 'GetHistoryLinkTrail') |
| 82 | + if ( !$editChanged && $content_actions['edit'] != null ) { |
| 83 | + $content_actions['edit']['href'] = wfAppendQuery( $content_actions['edit']['href'], "dataset=$dc" ); |
| 84 | + } |
| 85 | + |
| 86 | + $content_actions['history']['href'] = wfAppendQuery( $content_actions['history']['href'], "dataset=$dc" ); |
| 87 | + |
| 88 | + return true; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * FIXME: This does not seem to do anything, need to check whether the |
| 93 | + * preferences are still being detected. |
| 94 | + */ |
| 95 | + public static function onGetPreferences( $user, &$preferences ) { |
| 96 | + $datasets = wdGetDatasets(); |
| 97 | + foreach ( $datasets as $datasetid => $dataset ) { |
| 98 | + $datasetarray[$dataset->fetchName()] = $datasetid; |
| 99 | + } |
| 100 | + $preferences['ow_uipref_datasets'] = array( |
| 101 | + 'type' => 'multiselect', |
| 102 | + 'options' => $datasetarray, |
| 103 | + 'section' => 'omegawiki', |
| 104 | + 'label' => wfMsg( 'ow_shown_datasets' ), |
| 105 | + 'prefix' => 'ow_datasets-', |
| 106 | + ); |
| 107 | + return true; |
| 108 | + } |
| 109 | + |
| 110 | + public static function onArticleFromTitle( &$title, &$article ) { |
| 111 | + if ( self::isWikidataNs( $title ) ) { |
| 112 | + $article = new WikidataArticle( $title ); |
| 113 | + } |
| 114 | + return true; |
| 115 | + } |
| 116 | + |
| 117 | + public static function onCustomEditor( $article, $user ) { |
| 118 | + if ( self::isWikidataNs( $article->getTitle() ) ) { |
| 119 | + $editor = new WikidataEditPage( $article ); |
| 120 | + $editor->edit(); |
| 121 | + return false; |
| 122 | + } |
| 123 | + return true; |
| 124 | + } |
| 125 | + |
| 126 | + public static function onMediaWikiPerformAction( $output, $article, $title, $user, $request, $wiki ) { |
| 127 | + $action = $request->getVal( 'action' ); |
| 128 | + if ( $action === 'history' && self::isWikidataNs( $title ) ) { |
| 129 | + $history = new WikidataPageHistory( $article ); |
| 130 | + $history->history(); |
| 131 | + return false; |
| 132 | + } |
| 133 | + return true; |
| 134 | + } |
| 135 | + |
| 136 | + public static function onAbortMove( $oldtitle, $newtitle, $user, &$error, $reason ) { |
| 137 | + if ( self::isWikidataNs( $oldtitle ) ) { |
| 138 | + $error = wfMsg( 'wikidata-handler-namespace-move-error' ); |
| 139 | + return false; |
| 140 | + } |
| 141 | + return true; |
| 142 | + } |
| 143 | +} |
Property changes on: trunk/extensions/Wikidata/Wikidata.hooks.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 144 | + native |
Index: trunk/extensions/Wikidata/App.php |
— | — | @@ -16,39 +16,70 @@ |
17 | 17 | 'descriptionmsg' => 'wikidata-desc', |
18 | 18 | ); |
19 | 19 | |
| 20 | +$wgExtensionCredits['specialpage'][] = array( |
| 21 | + 'name' => 'SpecialConceptMapping', |
| 22 | + 'author' => 'Kim Bruning', |
| 23 | +); |
| 24 | + |
| 25 | +$wgExtensionCredits['specialpage'][] = array( |
| 26 | + 'name' => 'SpecialCopy', |
| 27 | + 'author' => 'Alan Smithee', |
| 28 | +); |
| 29 | + |
20 | 30 | $dir = dirname( __FILE__ ) . '/'; |
21 | 31 | |
22 | | -$wgExtensionFunctions[] = 'initializeWikidata'; |
23 | | -$wgHooks[ 'BeforePageDisplay' ][] = 'addWikidataHeader'; |
24 | | -$wgHooks[ 'SkinTemplateTabs' ][] = 'modifyTabs'; |
25 | | -$wgHooks[ 'GetPreferences' ][] = 'efWikidataGetPreferences'; |
26 | | -$wgHooks[ 'ArticleFromTitle' ][] = 'efWikidataOverrideArticle'; |
27 | | -$wgHooks[ 'CustomEditor' ][] = 'efWikidataOverrideEditPage'; |
28 | | -$wgHooks[ 'MediaWikiPerformAction'][] = 'efWikidataOverridePageHistory'; |
29 | | -$wgHooks[ 'AbortMove' ][] = 'efWikidataHandlerNamespacePreventMove'; |
30 | | -$wgAutoloadClasses[ 'WikidataArticle' ] = $dir . 'includes/WikidataArticle.php'; |
31 | | -$wgAutoloadClasses[ 'WikidataEditPage' ] = $dir . 'includes/WikidataEditPage.php'; |
32 | | -$wgAutoloadClasses[ 'WikidataPageHistory' ] = $dir . 'includes/WikidataPageHistory.php'; |
33 | | -$wgAutoloadClasses[ 'ApiWikiData' ] = $dir . 'includes/api/ApiWikiData.php'; |
34 | | -$wgAutoloadClasses[ 'ApiWikiDataFormatBase'] = $dir . 'includes/api/ApiWikiDataFormatBase.php'; |
35 | | -$wgAutoloadClasses[ 'ApiWikiDataFormatXml' ] = $dir . 'includes/api/ApiWikiDataFormatXml.php'; |
| 32 | +require_once( $dir . 'OmegaWiki/Wikidata.php' ); |
| 33 | + |
36 | 34 | $wgAPIModules['wikidata'] = 'ApiWikiData'; |
37 | 35 | $wgExtensionMessagesFiles['Wikidata'] = $dir . 'Wikidata.i18n.php'; |
38 | 36 | |
| 37 | +$wgAutoloadClasses['WikidataHooks'] = $dir . 'Wikidata.hooks.php'; |
| 38 | + |
| 39 | +$wgAutoloadClasses['WikidataArticle' ] = $dir . 'includes/WikidataArticle.php'; |
| 40 | +$wgAutoloadClasses['WikidataEditPage' ] = $dir . 'includes/WikidataEditPage.php'; |
| 41 | +$wgAutoloadClasses['WikidataPageHistory' ] = $dir . 'includes/WikidataPageHistory.php'; |
| 42 | +$wgAutoloadClasses['ApiWikiData' ] = $dir . 'includes/api/ApiWikiData.php'; |
| 43 | +$wgAutoloadClasses['ApiWikiDataFormatBase'] = $dir . 'includes/api/ApiWikiDataFormatBase.php'; |
| 44 | +$wgAutoloadClasses['ApiWikiDataFormatXml' ] = $dir . 'includes/api/ApiWikiDataFormatXml.php'; |
| 45 | + |
39 | 46 | # FIXME: Rename this to reduce chance of collision. |
40 | 47 | $wgAutoloadClasses['OmegaWiki'] = $dir . 'OmegaWiki/OmegaWiki.php'; |
| 48 | +$wgAutoloadClasses['DataSet'] = $dir . 'OmegaWiki/Wikidata.php'; |
| 49 | +$wgAutoloadClasses['DefaultWikidataApplication'] = $dir . 'OmegaWiki/Wikidata.php'; |
41 | 50 | $wgAutoloadClasses['DefinedMeaning'] = $dir . 'OmegaWiki/DefinedMeaning.php'; |
| 51 | +$wgAutoloadClasses['DefinedMeaningModel'] = $dir . 'OmegaWiki/DefinedMeaningModel.php'; |
42 | 52 | $wgAutoloadClasses['NeedsTranslationTo'] = $dir . 'OmegaWiki/NeedsTranslationTo.php'; |
43 | 53 | $wgAutoloadClasses['Search'] = $dir . 'OmegaWiki/Search.php'; |
44 | 54 | |
| 55 | +$wgAutoloadClasses['SpecialSuggest'] = $dir . 'OmegaWiki/SpecialSuggest.php'; |
| 56 | +$wgAutoloadClasses['SpecialSelect'] = $dir . 'OmegaWiki/SpecialSelect.php'; |
| 57 | +$wgAutoloadClasses['SpecialDatasearch'] = $dir . 'OmegaWiki/SpecialDatasearch.php'; |
| 58 | +$wgAutoloadClasses['SpecialTransaction'] = $dir . 'OmegaWiki/SpecialTransaction.php'; |
| 59 | +$wgAutoloadClasses['SpecialNeedsTranslation'] = $dir . 'OmegaWiki/SpecialNeedsTranslation.php'; |
| 60 | +$wgAutoloadClasses['SpecialImportLangNames'] = $dir . 'OmegaWiki/SpecialImportLangNames.php'; |
| 61 | +$wgAutoloadClasses['SpecialAddCollection'] = $dir . 'OmegaWiki/SpecialAddCollection.php'; |
| 62 | +$wgAutoloadClasses['SpecialConceptMapping'] = $dir . 'OmegaWiki/SpecialConceptMapping.php'; |
| 63 | +$wgAutoloadClasses['SpecialCopy'] = $dir . 'OmegaWiki/SpecialCopy.php'; |
| 64 | +$wgAutoloadClasses['SpecialExportTSV'] = $dir . 'OmegaWiki/SpecialExportTSV.php'; |
| 65 | +$wgAutoloadClasses['SpecialImportTSV'] = $dir . 'OmegaWiki/SpecialImportTSV.php'; |
| 66 | +$wgAutoloadClasses['SpecialOWStatistics'] = $dir . 'OmegaWiki/SpecialOWStatistics.php'; |
| 67 | + |
45 | 68 | # FIXME: These should be modified to make Wikidata more reusable. |
46 | 69 | $wgAvailableRights[] = 'editwikidata-uw'; |
47 | 70 | $wgAvailableRights[] = 'deletewikidata-uw'; |
48 | 71 | $wgAvailableRights[] = 'wikidata-copy'; |
| 72 | +$wgAvailableRights[] = 'languagenames'; |
| 73 | +$wgAvailableRights[] = 'addcollection'; |
| 74 | +$wgAvailableRights[] = 'exporttsv'; |
| 75 | +$wgAvailableRights[] = 'importtsv'; |
49 | 76 | $wgGroupPermissions['wikidata-omega']['editwikidata-uw'] = true; |
50 | 77 | $wgGroupPermissions['wikidata-omega']['deletewikidata-uw'] = true; |
51 | 78 | $wgGroupPermissions['wikidata-copy']['wikidata-copy'] = true; |
52 | 79 | $wgGroupPermissions['wikidata-omega']['wikidata-copy'] = true; |
| 80 | +$wgGroupPermissions['bureaucrat']['languagenames'] = true; |
| 81 | +$wgGroupPermissions['bureaucrat']['addcollection'] = true; |
| 82 | +$wgGroupPermissions['bureaucrat']['exporttsv'] = true; |
| 83 | +$wgGroupPermissions['bureaucrat']['importtsv'] = true; |
53 | 84 | |
54 | 85 | // Wikidata Configuration. |
55 | 86 | |
— | — | @@ -56,7 +87,7 @@ |
57 | 88 | # $wgCustomHandlerPath = array( '*' => "{$IP}/extensions/Wikidata/OmegaWiki/" ); |
58 | 89 | |
59 | 90 | # Array of namespace ids and the handler classes they use. |
60 | | -//$wdHandlerClasses = array(); |
| 91 | +$wdHandlerClasses = array(); |
61 | 92 | # Path to the handler class directory, will be deprecated in favor of autoloading shortly. |
62 | 93 | //$wdHandlerPath = ''; |
63 | 94 | |
— | — | @@ -97,7 +128,7 @@ |
98 | 129 | $wgDefaultGoPrefix = 'Expression:'; |
99 | 130 | $wgDefaultClassMids = array( 402295 ); |
100 | 131 | |
101 | | -require_once( "$IP/extensions/Wikidata/OmegaWiki/GotoSourceTemplate.php" ); |
| 132 | +require_once( $dir . 'OmegaWiki/GotoSourceTemplate.php' ); |
102 | 133 | $wgGotoSourceTemplates = array( 5 => $swissProtGotoSourceTemplate ); |
103 | 134 | |
104 | 135 | # The site prefix allows us to have multiple sets of customized |
— | — | @@ -105,181 +136,29 @@ |
106 | 137 | # in a single database. |
107 | 138 | if ( !isset( $wdSiteContext ) ) $wdSiteContext = "uw"; |
108 | 139 | |
109 | | -require_once( "{$IP}/extensions/Wikidata/SpecialLanguages.php" ); |
| 140 | +$wgRecordSetLanguage = 0; |
110 | 141 | |
111 | | -# FIXME: These should be migrated to make Wikidata more reusable. |
112 | | -require_once( "{$IP}/extensions/Wikidata/OmegaWiki/SpecialSuggest.php" ); |
113 | | -require_once( "{$IP}/extensions/Wikidata/OmegaWiki/SpecialSelect.php" ); |
114 | | -require_once( "{$IP}/extensions/Wikidata/OmegaWiki/SpecialDatasearch.php" ); |
115 | | -require_once( "{$IP}/extensions/Wikidata/OmegaWiki/SpecialTransaction.php" ); |
116 | | -require_once( "{$IP}/extensions/Wikidata/OmegaWiki/SpecialNeedsTranslation.php" ); |
117 | | -require_once( "{$IP}/extensions/Wikidata/OmegaWiki/SpecialImportLangNames.php" ); |
118 | | -require_once( "{$IP}/extensions/Wikidata/OmegaWiki/SpecialAddCollection.php" ); |
119 | | -require_once( "{$IP}/extensions/Wikidata/OmegaWiki/SpecialConceptMapping.php" ); |
120 | | -require_once( "{$IP}/extensions/Wikidata/OmegaWiki/SpecialCopy.php" ); |
121 | | -require_once( "{$IP}/extensions/Wikidata/OmegaWiki/SpecialExportTSV.php" ); |
122 | | -require_once( "{$IP}/extensions/Wikidata/OmegaWiki/SpecialImportTSV.php" ); |
123 | | -require_once( "{$IP}/extensions/Wikidata/OmegaWiki/SpecialOWStatistics.php" ); |
| 142 | +require_once( $dir . '/SpecialLanguages.php' ); |
124 | 143 | |
125 | | -require_once( "{$IP}/extensions/Wikidata/LocalApp.php" ); |
| 144 | +$wgSpecialPages['Suggest'] = 'SpecialSuggest'; |
| 145 | +$wgSpecialPages['Select'] = 'SpecialSelect'; |
| 146 | +$wgSpecialPages['Datasearch'] = 'SpecialDatasearch'; |
| 147 | +$wgSpecialPages['Transaction'] = 'SpecialTransaction'; |
| 148 | +$wgSpecialPages['NeedsTranslation'] = 'SpecialNeedsTranslation'; |
| 149 | +$wgSpecialPages['ImportLangNames'] = 'SpecialImportLangNames'; |
| 150 | +$wgSpecialPages['AddCollection'] = 'SpecialAddCollection'; |
| 151 | +$wgSpecialPages['ConceptMapping'] = 'SpecialConceptMapping'; |
| 152 | +$wgSpecialPages['Copy'] = 'SpecialCopy'; |
| 153 | +$wgSpecialPages['ExportTSV'] = 'SpecialExportTSV'; |
| 154 | +$wgSpecialPages['ImportTSV'] = 'SpecialImportTSV'; |
| 155 | +$wgSpecialPages['ow_statistics'] = 'SpecialOWStatistics'; |
126 | 156 | |
127 | | -# FIXME: This should be migrated to make Wikidata more reusable. |
128 | | -function addWikidataHeader( &$out, &$skin ) { |
129 | | - global $wgScriptPath; |
130 | | - $out->addScript( "<script type='text/javascript' src='$wgScriptPath/extensions/Wikidata/OmegaWiki/suggest.js'></script>" ); |
131 | | - $out->addScript( "<script type='text/javascript' src='$wgScriptPath/extensions/Wikidata/OmegaWiki/omegawiki-ajax.js'></script>" ); |
132 | | - |
133 | | - global $wgLang; |
134 | | - if ( $wgLang->isRTL() ) { |
135 | | - $rtl = '-rtl'; |
136 | | - } else { |
137 | | - $rtl = ''; |
138 | | - } |
| 157 | +$wgHooks['BeforePageDisplay'][] = 'WikidataHooks::onBeforePageDisplay'; |
| 158 | +$wgHooks['SkinTemplateTabs'][] = 'WikidataHooks::onSkinTemplateTabs'; |
| 159 | +$wgHooks['GetPreferences'][] = 'WikidataHooks::onGetPreferences'; |
| 160 | +$wgHooks['ArticleFromTitle'][] = 'WikidataHooks::onArticleFromTitle'; |
| 161 | +$wgHooks['CustomEditor'][] = 'WikidataHooks::onCustomEditor'; |
| 162 | +$wgHooks['MediaWikiPerformAction'][] = 'WikidataHooks::onMediaWikiPerformAction'; |
| 163 | +$wgHooks['AbortMove'][] = 'WikidataHooks::onAbortMove'; |
139 | 164 | |
140 | | - $out->addLink( array( 'rel' => 'stylesheet', 'type' => 'text/css', 'media' => 'screen', 'href' => "$wgScriptPath/extensions/Wikidata/OmegaWiki/suggest$rtl.css" ) ); |
141 | | - $out->addLink( array( 'rel' => 'stylesheet', 'type' => 'text/css', 'media' => 'screen', 'href' => "$wgScriptPath/extensions/Wikidata/OmegaWiki/tables$rtl.css" ) ); |
142 | | - return true; |
143 | | -} |
144 | | - |
145 | | -function wdIsWikidataNs() { |
146 | | - global $wgTitle, $wdHandlerClasses; |
147 | | - return array_key_exists( $wgTitle->getNamespace(), $wdHandlerClasses ); |
148 | | - |
149 | | -} |
150 | | - |
151 | | -function addWikidataEditLinkTrail( &$trail ) { |
152 | | - if ( wdIsWikidataNs() ) { |
153 | | - $dc = wdGetDatasetContext(); |
154 | | - $trail = "&dataset=$dc"; |
155 | | - } |
156 | | - return true; |
157 | | -} |
158 | | - |
159 | | -function addHistoryLinkTrail( &$trail ) { |
160 | | - if ( wdIsWikidataNs() ) { |
161 | | - $dc = wdGetDatasetContext(); |
162 | | - $trail = "&dataset=$dc"; |
163 | | - } |
164 | | - return true; |
165 | | -} |
166 | | - |
167 | | -/** |
168 | | - * Purpose: Add custom tabs |
169 | | - * |
170 | | - * When editing in read-only data-set, if you have the copy permission, you can |
171 | | - * make a copy into the designated community dataset and edit the data there. |
172 | | - * This is accessible through an 'edit copy' tab which is added below. |
173 | | - * |
174 | | - * @param $skin Skin as passed by MW |
175 | | - * @param $tabs as passed by MW |
176 | | - */ |
177 | | -function modifyTabs( $skin, $content_actions ) { |
178 | | - global $wgUser, $wgTitle, $wgCommunity_dc, $wdShowEditCopy, $wdHandlerClasses; |
179 | | - $dc = wdGetDataSetContext(); |
180 | | - $ns = $wgTitle->getNamespace(); |
181 | | - $editChanged = false; |
182 | | - if ( wdIsWikidataNs() && $wdHandlerClasses[ $ns ] == 'DefinedMeaning' ) { |
183 | | - |
184 | | - # Hackishly determine which DMID we're on by looking at the page title component |
185 | | - $tt = $wgTitle->getText(); |
186 | | - $rpos1 = strrpos( $tt, '(' ); |
187 | | - $rpos2 = strrpos( $tt, ')' ); |
188 | | - $dmid = ( $rpos1 && $rpos2 ) ? substr( $tt, $rpos1 + 1, $rpos2 - $rpos1 - 1 ) : 0; |
189 | | - if ( $dmid ) { |
190 | | - $copyTitle = SpecialPage::getTitleFor( 'Copy' ); |
191 | | - if ( wdIsWikidataNs() && $dc != $wgCommunity_dc && $wdShowEditCopy ) { |
192 | | - $editChanged = true; |
193 | | - $content_actions['edit'] = array( |
194 | | - 'class' => false, |
195 | | - 'text' => wfMsg( 'ow_nstab_edit_copy' ), |
196 | | - 'href' => $copyTitle->getLocalUrl( "action=copy&dmid=$dmid&dc1=$dc&dc2=$wgCommunity_dc" ) |
197 | | - ); |
198 | | - } |
199 | | - $content_actions['nstab-definedmeaning'] = array( |
200 | | - 'class' => 'selected', |
201 | | - 'text' => wfMsg( 'ow_nstab_definedmeaning' ), |
202 | | - 'href' => $wgTitle->getLocalUrl( "dataset=$dc" ) |
203 | | - ); |
204 | | - } |
205 | | - } |
206 | | - |
207 | | - // Prevent move tab being shown. |
208 | | - if( wdIsWikidataNs() ) unset( $content_actions['move'] ); |
209 | | - |
210 | | - // Add context dataset (old hooks 'GetEditLinkTrail' and 'GetHistoryLinkTrail') |
211 | | - if ( !$editChanged && $content_actions['edit'] != null ) { |
212 | | - addWikidataEditLinkTrail( $linkTrail ); |
213 | | - $content_actions['edit']['href'] = ( $content_actions['edit']['href'] . $linkTrail ); |
214 | | - } |
215 | | - addHistoryLinkTrail( $linkTrail ); |
216 | | - $content_actions['history']['href'] = ( $content_actions['history']['href'] . $linkTrail ); |
217 | | - |
218 | | - return true; |
219 | | -} |
220 | | - |
221 | | -function initializeWikidata() { |
222 | | - wfLoadExtensionMessages( 'Wikidata' ); |
223 | | - |
224 | | - $dbr = wfGetDB( DB_MASTER ); |
225 | | - $dbr->query( 'SET NAMES utf8' ); |
226 | | - |
227 | | - global $wgRecordSetLanguage; |
228 | | - $wgRecordSetLanguage = 0; |
229 | | - |
230 | | - global $wgLang, $wgOut; |
231 | | - if ( $wgLang->isRTL() ) { |
232 | | - # FIXME: Why are we including Gadget CSS here, this is Wikidata? |
233 | | - $wgOut->addHTML( '<style type="text/css">/*<![CDATA[*/ @import "/index.php?title=MediaWiki:Gadget-rtl.css&action=raw&ctype=text/css"; /*]]>*/</style>' ); |
234 | | - } |
235 | | - |
236 | | - return true; |
237 | | -} |
238 | | - |
239 | | -/** |
240 | | - * FIXME: This does not seem to do anything, need to check whether the |
241 | | - * preferences are still being detected. |
242 | | - */ |
243 | | -function efWikidataGetPreferences( $user, &$preferences ) { |
244 | | - $datasets = wdGetDatasets(); |
245 | | - foreach ( $datasets as $datasetid => $dataset ) { |
246 | | - $datasetarray[$dataset->fetchName()] = $datasetid; |
247 | | - } |
248 | | - $preferences['ow_uipref_datasets'] = array( |
249 | | - 'type' => 'multiselect', |
250 | | - 'options' => $datasetarray, |
251 | | - 'section' => 'omegawiki', |
252 | | - 'label' => wfMsg( 'ow_shown_datasets' ), |
253 | | - 'prefix' => 'ow_datasets-', |
254 | | - ); |
255 | | - return true; |
256 | | -} |
257 | | - |
258 | | -function efWikidataOverrideArticle( &$title, &$article ) { |
259 | | - global $wgLang, $wgRequest, $wgOut ; |
260 | | - if ( wdIsWikidataNs() ) $article = new WikidataArticle( $title ); |
261 | | - return true ; |
262 | | -} |
263 | | - |
264 | | -function efWikidataOverrideEditPage( $article, $user ) { |
265 | | - if ( wdIsWikidataNs() ) { |
266 | | - $editor = new WikidataEditPage( $article ); |
267 | | - $editor->edit(); |
268 | | - } |
269 | | - return !wdIsWikidataNs() ; |
270 | | -} |
271 | | - |
272 | | -function efWikidataOverridePageHistory( $output, $article, $title, $user, $request, $wiki ) { |
273 | | - $action = $request->getVal( 'action' ); |
274 | | - if ( $action === 'history' && wdIsWikidataNs() ) { |
275 | | - $history = new WikidataPageHistory( $article ); |
276 | | - $history->history(); |
277 | | - } |
278 | | - return !( $action === 'history' && wdIsWikidataNs() ); |
279 | | -} |
280 | | - |
281 | | -function efWikidataHandlerNamespacePreventMove( $oldtitle, $newtitle, $user, &$error, $reason ) { |
282 | | - if ( wdIsWikidataNs() ) { |
283 | | - $error = wfMsg( 'wikidata-handler-namespace-move-error' ); |
284 | | - } |
285 | | - return !wdIsWikidataNs(); |
286 | | -} |
| 165 | +require_once( "{$IP}/extensions/Wikidata/LocalApp.php" ); |
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialDatasearch.php |
— | — | @@ -2,364 +2,358 @@ |
3 | 3 | |
4 | 4 | if ( !defined( 'MEDIAWIKI' ) ) die(); |
5 | 5 | |
6 | | -$wgExtensionFunctions[] = 'wfSpecialDatasearch'; |
7 | | - |
8 | 6 | require_once( "Wikidata.php" ); |
9 | 7 | require_once( "WikiDataGlobals.php" ); |
10 | 8 | |
11 | | -function wfSpecialDatasearch() { |
12 | | - class SpecialDatasearch extends SpecialPage { |
13 | | - protected $externalIdentifierAttribute; |
14 | | - protected $collectionAttribute; |
15 | | - protected $collectionMemberAttribute; |
16 | | - protected $externalIdentifierMatchStructure; |
| 9 | +class SpecialDatasearch extends SpecialPage { |
| 10 | + protected $externalIdentifierAttribute; |
| 11 | + protected $collectionAttribute; |
| 12 | + protected $collectionMemberAttribute; |
| 13 | + protected $externalIdentifierMatchStructure; |
17 | 14 | |
18 | | - protected $spellingAttribute; |
19 | | - protected $languageAttribute; |
| 15 | + protected $spellingAttribute; |
| 16 | + protected $languageAttribute; |
20 | 17 | |
21 | | - protected $expressionStructure; |
22 | | - protected $expressionAttribute; |
| 18 | + protected $expressionStructure; |
| 19 | + protected $expressionAttribute; |
23 | 20 | |
24 | | - protected $definedMeaningAttribute; |
25 | | - protected $definitionAttribute; |
| 21 | + protected $definedMeaningAttribute; |
| 22 | + protected $definitionAttribute; |
26 | 23 | |
27 | | - protected $meaningStructure; |
28 | | - protected $meaningAttribute; |
| 24 | + protected $meaningStructure; |
| 25 | + protected $meaningAttribute; |
29 | 26 | |
30 | | - function SpecialDatasearch() { |
31 | | - parent::__construct( 'DataSearch' ); |
32 | | - } |
| 27 | + function SpecialDatasearch() { |
| 28 | + parent::__construct( 'DataSearch' ); |
| 29 | + } |
33 | 30 | |
34 | | - function execute( $parameter ) { |
35 | | - global $wgOut; |
| 31 | + function execute( $parameter ) { |
| 32 | + global $wgOut; |
36 | 33 | |
37 | | - initializeOmegaWikiAttributes( new ViewInformation() ); |
| 34 | + initializeOmegaWikiAttributes( new ViewInformation() ); |
38 | 35 | |
39 | | - global |
40 | | - $definedMeaningReferenceType, |
41 | | - $wgDefinedMeaning; |
| 36 | + global |
| 37 | + $definedMeaningReferenceType, |
| 38 | + $wgDefinedMeaning; |
42 | 39 | |
43 | | - require_once( "WikiDataGlobals.php" ); |
44 | | - require_once( "forms.php" ); |
45 | | - require_once( "type.php" ); |
46 | | - require_once( "ViewInformation.php" ); |
47 | | - require_once( "WikiDataAPI.php" ); |
48 | | - require_once( "OmegaWikiAttributes.php" ); |
49 | | - require_once( "OmegaWikiRecordSets.php" ); |
50 | | - require_once( "OmegaWikiEditors.php" ); |
| 40 | + require_once( "WikiDataGlobals.php" ); |
| 41 | + require_once( "forms.php" ); |
| 42 | + require_once( "type.php" ); |
| 43 | + require_once( "ViewInformation.php" ); |
| 44 | + require_once( "WikiDataAPI.php" ); |
| 45 | + require_once( "OmegaWikiAttributes.php" ); |
| 46 | + require_once( "OmegaWikiRecordSets.php" ); |
| 47 | + require_once( "OmegaWikiEditors.php" ); |
51 | 48 | |
52 | | - $wgOut->setPageTitle( wfMsg( 'search' ) ); |
| 49 | + $wgOut->setPageTitle( wfMsg( 'search' ) ); |
53 | 50 | |
54 | | - $this->spellingAttribute = new Attribute( "found-word", wfMsg( 'datasearch_found_word' ), "short-text" ); |
55 | | - $this->languageAttribute = new Attribute( "language", wfMsg( 'ow_Language' ), "language" ); |
| 51 | + $this->spellingAttribute = new Attribute( "found-word", wfMsg( 'datasearch_found_word' ), "short-text" ); |
| 52 | + $this->languageAttribute = new Attribute( "language", wfMsg( 'ow_Language' ), "language" ); |
56 | 53 | |
57 | | - $this->expressionStructure = new Structure( $this->spellingAttribute, $this->languageAttribute ); |
58 | | - $this->expressionAttribute = new Attribute( "expression", wfMsg( 'ow_Expression' ), $this->expressionStructure ); |
| 54 | + $this->expressionStructure = new Structure( $this->spellingAttribute, $this->languageAttribute ); |
| 55 | + $this->expressionAttribute = new Attribute( "expression", wfMsg( 'ow_Expression' ), $this->expressionStructure ); |
59 | 56 | |
60 | | - $this->definedMeaningAttribute = new Attribute( $wgDefinedMeaning, wfMsg( 'ow_DefinedMeaning' ), $definedMeaningReferenceType ); |
61 | | - $this->definitionAttribute = new Attribute( "definition", wfMsg( 'ow_Definition' ), "definition" ); |
| 57 | + $this->definedMeaningAttribute = new Attribute( $wgDefinedMeaning, wfMsg( 'ow_DefinedMeaning' ), $definedMeaningReferenceType ); |
| 58 | + $this->definitionAttribute = new Attribute( "definition", wfMsg( 'ow_Definition' ), "definition" ); |
62 | 59 | |
63 | | - $this->meaningStructure = new Structure( $this->definedMeaningAttribute, $this->definitionAttribute ); |
64 | | - $this->meaningAttribute = new Attribute( "meaning", wfMsg( 'datasearch_meaning' ), $this->meaningStructure ); |
| 60 | + $this->meaningStructure = new Structure( $this->definedMeaningAttribute, $this->definitionAttribute ); |
| 61 | + $this->meaningAttribute = new Attribute( "meaning", wfMsg( 'datasearch_meaning' ), $this->meaningStructure ); |
65 | 62 | |
66 | | - $this->externalIdentifierAttribute = new Attribute( "external-identifier", wfMsg( 'datasearch_ext_identifier' ), "short-text" ); |
67 | | - $this->collectionAttribute = new Attribute( "collection", wfMsg( 'ow_Collection' ), $definedMeaningReferenceType ); |
68 | | - $this->collectionMemberAttribute = new Attribute( "collection-member", wfMsg( 'ow_CollectionMember' ), $definedMeaningReferenceType ); |
| 63 | + $this->externalIdentifierAttribute = new Attribute( "external-identifier", wfMsg( 'datasearch_ext_identifier' ), "short-text" ); |
| 64 | + $this->collectionAttribute = new Attribute( "collection", wfMsg( 'ow_Collection' ), $definedMeaningReferenceType ); |
| 65 | + $this->collectionMemberAttribute = new Attribute( "collection-member", wfMsg( 'ow_CollectionMember' ), $definedMeaningReferenceType ); |
69 | 66 | |
70 | | - $this->externalIdentifierMatchStructure = new Structure( |
71 | | - $this->externalIdentifierAttribute, |
72 | | - $this->collectionAttribute, |
73 | | - $this->collectionMemberAttribute |
74 | | - ); |
| 67 | + $this->externalIdentifierMatchStructure = new Structure( |
| 68 | + $this->externalIdentifierAttribute, |
| 69 | + $this->collectionAttribute, |
| 70 | + $this->collectionMemberAttribute |
| 71 | + ); |
75 | 72 | |
76 | | - if ( array_key_exists( 'search-text', $_GET ) ) { |
77 | | - $searchText = ltrim( $_GET['search-text'] ); |
78 | | - } else { |
79 | | - $searchText = null; |
80 | | - } |
81 | | - |
82 | | - if ( isset( $_GET['go'] ) ) |
83 | | - $this->go( $searchText ); |
84 | | - else |
85 | | - $this->search( $searchText ); |
| 73 | + if ( array_key_exists( 'search-text', $_GET ) ) { |
| 74 | + $searchText = ltrim( $_GET['search-text'] ); |
| 75 | + } else { |
| 76 | + $searchText = null; |
86 | 77 | } |
87 | 78 | |
88 | | - function go( $searchText ) { |
89 | | - global |
90 | | - $wgScript, $wgOut; |
| 79 | + if ( isset( $_GET['go'] ) ) |
| 80 | + $this->go( $searchText ); |
| 81 | + else |
| 82 | + $this->search( $searchText ); |
| 83 | + } |
91 | 84 | |
92 | | - $expressionMeaningIds = getExpressionMeaningIds( $searchText ); |
| 85 | + function go( $searchText ) { |
| 86 | + global |
| 87 | + $wgScript, $wgOut; |
93 | 88 | |
94 | | - if ( count( $expressionMeaningIds ) > 0 ) { |
95 | | - if ( count( $expressionMeaningIds ) == 1 ) |
96 | | - $wgOut->redirect( definedMeaningIdAsURL( $expressionMeaningIds[0] ) ); |
97 | | - else |
98 | | - $wgOut->redirect( spellingAsURL( $searchText ) ); |
99 | | - } |
100 | | - else { |
101 | | - $collectionMemberId = getAnyDefinedMeaningWithSourceIdentifier( $searchText ); |
| 89 | + $expressionMeaningIds = getExpressionMeaningIds( $searchText ); |
102 | 90 | |
103 | | - if ( $collectionMemberId != 0 ) |
104 | | - $wgOut->redirect( definedMeaningIdAsURL( $collectionMemberId ) ); |
105 | | - else |
106 | | - $wgOut->redirect( spellingAsURL( $searchText ) ); |
107 | | - } |
| 91 | + if ( count( $expressionMeaningIds ) > 0 ) { |
| 92 | + if ( count( $expressionMeaningIds ) == 1 ) |
| 93 | + $wgOut->redirect( definedMeaningIdAsURL( $expressionMeaningIds[0] ) ); |
| 94 | + else |
| 95 | + $wgOut->redirect( spellingAsURL( $searchText ) ); |
108 | 96 | } |
| 97 | + else { |
| 98 | + $collectionMemberId = getAnyDefinedMeaningWithSourceIdentifier( $searchText ); |
109 | 99 | |
110 | | - function search( $searchText ) { |
111 | | - global |
112 | | - $wgOut, $wgRequest, $wgFilterLanguageId, |
113 | | - $wgSearchWithinWordsDefaultValue, $wgSearchWithinExternalIdentifiersDefaultValue, |
114 | | - $wgShowSearchWithinExternalIdentifiersOption, $wgShowSearchWithinWordsOption; |
| 100 | + if ( $collectionMemberId != 0 ) |
| 101 | + $wgOut->redirect( definedMeaningIdAsURL( $collectionMemberId ) ); |
| 102 | + else |
| 103 | + $wgOut->redirect( spellingAsURL( $searchText ) ); |
| 104 | + } |
| 105 | + } |
115 | 106 | |
116 | | - $collectionId = $wgRequest->getInt( "collection" ); |
117 | | - $languageId = $wgRequest->getInt( "language" ); |
118 | | - $withinWords = $wgRequest->getBool( "within-words" ); |
119 | | - $withinExternalIdentifiers = $wgRequest->getBool( "within-external-identifiers" ); |
| 107 | + function search( $searchText ) { |
| 108 | + global |
| 109 | + $wgOut, $wgRequest, $wgFilterLanguageId, |
| 110 | + $wgSearchWithinWordsDefaultValue, $wgSearchWithinExternalIdentifiersDefaultValue, |
| 111 | + $wgShowSearchWithinExternalIdentifiersOption, $wgShowSearchWithinWordsOption; |
120 | 112 | |
121 | | - if ( !$withinWords && !$withinExternalIdentifiers ) { |
122 | | - $withinWords = $wgSearchWithinWordsDefaultValue; |
123 | | - $withinExternalIdentifiers = $wgSearchWithinExternalIdentifiersDefaultValue; |
124 | | - } |
| 113 | + $collectionId = $wgRequest->getInt( "collection" ); |
| 114 | + $languageId = $wgRequest->getInt( "language" ); |
| 115 | + $withinWords = $wgRequest->getBool( "within-words" ); |
| 116 | + $withinExternalIdentifiers = $wgRequest->getBool( "within-external-identifiers" ); |
125 | 117 | |
126 | | - $languageName = languageIdAsText( $languageId ); |
127 | | - $options = array(); |
128 | | - $options[wfMsg( 'datasearch_search_text' )] = getTextBox( 'search-text', $searchText ); |
| 118 | + if ( !$withinWords && !$withinExternalIdentifiers ) { |
| 119 | + $withinWords = $wgSearchWithinWordsDefaultValue; |
| 120 | + $withinExternalIdentifiers = $wgSearchWithinExternalIdentifiersDefaultValue; |
| 121 | + } |
129 | 122 | |
130 | | - if ( $wgFilterLanguageId == 0 ) |
131 | | - $options[wfMsg( 'datasearch_language' )] = getSuggest( 'language', "language", array(), $languageId, $languageName ); |
132 | | - else |
133 | | - $languageId = $wgFilterLanguageId; |
| 123 | + $languageName = languageIdAsText( $languageId ); |
| 124 | + $options = array(); |
| 125 | + $options[wfMsg( 'datasearch_search_text' )] = getTextBox( 'search-text', $searchText ); |
134 | 126 | |
135 | | - $options[wfMsg( 'ow_Collection_colon' )] = getSuggest( 'collection', 'collection', array(), $collectionId, collectionIdAsText( $collectionId ) ); |
| 127 | + if ( $wgFilterLanguageId == 0 ) |
| 128 | + $options[wfMsg( 'datasearch_language' )] = getSuggest( 'language', "language", array(), $languageId, $languageName ); |
| 129 | + else |
| 130 | + $languageId = $wgFilterLanguageId; |
136 | 131 | |
137 | | - if ( $wgShowSearchWithinWordsOption ) |
138 | | - $options[wfMsg( 'datasearch_within_words' )] = getCheckBox( 'within-words', $withinWords ); |
139 | | - else |
140 | | - $withinWords = $wgSearchWithinWordsDefaultValue; |
| 132 | + $options[wfMsg( 'ow_Collection_colon' )] = getSuggest( 'collection', 'collection', array(), $collectionId, collectionIdAsText( $collectionId ) ); |
141 | 133 | |
142 | | - if ( $wgShowSearchWithinExternalIdentifiersOption ) |
143 | | - $options[wfMsg( 'datasearch_within_ext_ids' )] = getCheckBox( 'within-external-identifiers', $withinExternalIdentifiers ); |
144 | | - else |
145 | | - $withinExternalIdentifiers = $wgSearchWithinExternalIdentifiersDefaultValue; |
| 134 | + if ( $wgShowSearchWithinWordsOption ) |
| 135 | + $options[wfMsg( 'datasearch_within_words' )] = getCheckBox( 'within-words', $withinWords ); |
| 136 | + else |
| 137 | + $withinWords = $wgSearchWithinWordsDefaultValue; |
146 | 138 | |
147 | | - $wgOut->addHTML( getOptionPanel( $options ) ); |
| 139 | + if ( $wgShowSearchWithinExternalIdentifiersOption ) |
| 140 | + $options[wfMsg( 'datasearch_within_ext_ids' )] = getCheckBox( 'within-external-identifiers', $withinExternalIdentifiers ); |
| 141 | + else |
| 142 | + $withinExternalIdentifiers = $wgSearchWithinExternalIdentifiersDefaultValue; |
148 | 143 | |
149 | | - if ( $withinWords ) { |
150 | | - if ( $languageId != 0 && $languageName != "" ) |
151 | | - $wgOut->addHTML( '<h1>' . wfMsg( 'datasearch_match_words_lang', $languageName, $searchText ) . '</h1>' ); |
152 | | - else |
153 | | - $wgOut->addHTML( '<h1>' . wfMsg( 'datasearch_match_words', $searchText ) . '</h1>' ); |
| 144 | + $wgOut->addHTML( getOptionPanel( $options ) ); |
154 | 145 | |
155 | | - $resultCount = $this->searchWordsCount( $searchText, $collectionId, $languageId ) ; |
156 | | - $wgOut->addHTML( '<p>' . wfMsgExt( 'datasearch_showing_only', 'parsemag', 100 , $resultCount ) . '</p>' ); |
| 146 | + if ( $withinWords ) { |
| 147 | + if ( $languageId != 0 && $languageName != "" ) |
| 148 | + $wgOut->addHTML( '<h1>' . wfMsg( 'datasearch_match_words_lang', $languageName, $searchText ) . '</h1>' ); |
| 149 | + else |
| 150 | + $wgOut->addHTML( '<h1>' . wfMsg( 'datasearch_match_words', $searchText ) . '</h1>' ); |
157 | 151 | |
158 | | - $wgOut->addHTML( $this->searchWords( $searchText, $collectionId, $languageId ) ); |
159 | | - } |
| 152 | + $resultCount = $this->searchWordsCount( $searchText, $collectionId, $languageId ) ; |
| 153 | + $wgOut->addHTML( '<p>' . wfMsgExt( 'datasearch_showing_only', 'parsemag', 100 , $resultCount ) . '</p>' ); |
160 | 154 | |
161 | | - if ( $withinExternalIdentifiers ) { |
162 | | - $wgOut->addHTML( '<h1>' . wfMsg( 'datasearch_match_ext_ids', $searchText ) . '</i></h1>' ); |
163 | | - $wgOut->addHTML( '<p>' . wfMsgExt( 'datasearch_showing_only', 'parsemag', 100 ) . '</p>' ); |
164 | | - |
165 | | - $wgOut->addHTML( $this->searchExternalIdentifiers( $searchText, $collectionId ) ); |
166 | | - } |
| 155 | + $wgOut->addHTML( $this->searchWords( $searchText, $collectionId, $languageId ) ); |
167 | 156 | } |
168 | 157 | |
169 | | - function getSpellingRestriction( $spelling, $tableColumn ) { |
170 | | - $dbr = wfGetDB( DB_SLAVE ); |
| 158 | + if ( $withinExternalIdentifiers ) { |
| 159 | + $wgOut->addHTML( '<h1>' . wfMsg( 'datasearch_match_ext_ids', $searchText ) . '</i></h1>' ); |
| 160 | + $wgOut->addHTML( '<p>' . wfMsgExt( 'datasearch_showing_only', 'parsemag', 100 ) . '</p>' ); |
171 | 161 | |
172 | | - if ( trim( $spelling ) != '' ) |
173 | | - return " AND " . $tableColumn . " LIKE " . $dbr->addQuotes( "%$spelling%" ); |
174 | | - else |
175 | | - return ""; |
| 162 | + $wgOut->addHTML( $this->searchExternalIdentifiers( $searchText, $collectionId ) ); |
176 | 163 | } |
| 164 | + } |
177 | 165 | |
178 | | - function getSpellingOrderBy( $spelling ) { |
179 | | - if ( trim( $spelling ) != '' ) |
180 | | - return "position ASC, "; |
181 | | - else |
182 | | - return ""; |
183 | | - } |
| 166 | + function getSpellingRestriction( $spelling, $tableColumn ) { |
| 167 | + $dbr = wfGetDB( DB_SLAVE ); |
184 | 168 | |
185 | | - function getPositionSelectColumn( $spelling, $tableColumn ) { |
186 | | - $dbr = wfGetDB( DB_SLAVE ); |
| 169 | + if ( trim( $spelling ) != '' ) |
| 170 | + return " AND " . $tableColumn . " LIKE " . $dbr->addQuotes( "%$spelling%" ); |
| 171 | + else |
| 172 | + return ""; |
| 173 | + } |
187 | 174 | |
188 | | - if ( trim( $spelling ) != '' ) |
189 | | - return "INSTR(LCASE(" . $tableColumn . "), LCASE(" . $dbr->addQuotes( "$spelling" ) . ")) as position, "; |
190 | | - else |
191 | | - return ""; |
192 | | - } |
| 175 | + function getSpellingOrderBy( $spelling ) { |
| 176 | + if ( trim( $spelling ) != '' ) |
| 177 | + return "position ASC, "; |
| 178 | + else |
| 179 | + return ""; |
| 180 | + } |
193 | 181 | |
194 | | - function searchWords( $text, $collectionId, $languageId ) { |
195 | | - $dc = wdGetDataSetContext(); |
196 | | - $dbr = wfGetDB( DB_SLAVE ); |
| 182 | + function getPositionSelectColumn( $spelling, $tableColumn ) { |
| 183 | + $dbr = wfGetDB( DB_SLAVE ); |
197 | 184 | |
198 | | - $sql = |
199 | | - "SELECT " . $this->getPositionSelectColumn( $text, "{$dc}_expression.spelling" ) . " {$dc}_syntrans.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling AS spelling, {$dc}_expression.language_id AS language_id " . |
200 | | - "FROM {$dc}_expression, {$dc}_syntrans "; |
| 185 | + if ( trim( $spelling ) != '' ) |
| 186 | + return "INSTR(LCASE(" . $tableColumn . "), LCASE(" . $dbr->addQuotes( "$spelling" ) . ")) as position, "; |
| 187 | + else |
| 188 | + return ""; |
| 189 | + } |
201 | 190 | |
202 | | - if ( $collectionId > 0 ) |
203 | | - $sql .= ", {$dc}_collection_contents "; |
| 191 | + function searchWords( $text, $collectionId, $languageId ) { |
| 192 | + $dc = wdGetDataSetContext(); |
| 193 | + $dbr = wfGetDB( DB_SLAVE ); |
204 | 194 | |
205 | | - $sql .= |
206 | | - "WHERE {$dc}_expression.expression_id={$dc}_syntrans.expression_id AND {$dc}_syntrans.identical_meaning=1 " . |
207 | | - " AND " . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
208 | | - " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) . |
209 | | - $this->getSpellingRestriction( $text, 'spelling' ); |
| 195 | + $sql = |
| 196 | + "SELECT " . $this->getPositionSelectColumn( $text, "{$dc}_expression.spelling" ) . " {$dc}_syntrans.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling AS spelling, {$dc}_expression.language_id AS language_id " . |
| 197 | + "FROM {$dc}_expression, {$dc}_syntrans "; |
210 | 198 | |
211 | | - if ( $collectionId > 0 ) |
212 | | - $sql .= |
213 | | - " AND {$dc}_collection_contents.member_mid={$dc}_syntrans.defined_meaning_id " . |
214 | | - " AND {$dc}_collection_contents.collection_id=" . $collectionId . |
215 | | - " AND " . getLatestTransactionRestriction( "{$dc}_collection_contents" ); |
| 199 | + if ( $collectionId > 0 ) |
| 200 | + $sql .= ", {$dc}_collection_contents "; |
216 | 201 | |
217 | | - if ( $languageId > 0 ) |
218 | | - $sql .= |
219 | | - " AND {$dc}_expression.language_id=$languageId"; |
| 202 | + $sql .= |
| 203 | + "WHERE {$dc}_expression.expression_id={$dc}_syntrans.expression_id AND {$dc}_syntrans.identical_meaning=1 " . |
| 204 | + " AND " . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
| 205 | + " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) . |
| 206 | + $this->getSpellingRestriction( $text, 'spelling' ); |
220 | 207 | |
| 208 | + if ( $collectionId > 0 ) |
221 | 209 | $sql .= |
222 | | - " ORDER BY " . $this->getSpellingOrderBy( $text ) . "{$dc}_expression.spelling ASC limit 100"; |
| 210 | + " AND {$dc}_collection_contents.member_mid={$dc}_syntrans.defined_meaning_id " . |
| 211 | + " AND {$dc}_collection_contents.collection_id=" . $collectionId . |
| 212 | + " AND " . getLatestTransactionRestriction( "{$dc}_collection_contents" ); |
223 | 213 | |
224 | | - $queryResult = $dbr->query( $sql ); |
225 | | - $recordSet = $this->getWordsSearchResultAsRecordSet( $queryResult ); |
226 | | - $editor = $this->getWordsSearchResultEditor(); |
| 214 | + if ( $languageId > 0 ) |
| 215 | + $sql .= |
| 216 | + " AND {$dc}_expression.language_id=$languageId"; |
227 | 217 | |
228 | | - return $editor->view( new IdStack( "words" ), $recordSet ); |
229 | | - } |
| 218 | + $sql .= |
| 219 | + " ORDER BY " . $this->getSpellingOrderBy( $text ) . "{$dc}_expression.spelling ASC limit 100"; |
230 | 220 | |
231 | | -/** |
232 | | -* Gives the exact number of results (not limited to 100) |
233 | | -*/ |
234 | | - function searchWordsCount( $text, $collectionId, $languageId ) { |
235 | | - $dc = wdGetDataSetContext(); |
236 | | - $dbr = wfGetDB( DB_SLAVE ); |
| 221 | + $queryResult = $dbr->query( $sql ); |
| 222 | + $recordSet = $this->getWordsSearchResultAsRecordSet( $queryResult ); |
| 223 | + $editor = $this->getWordsSearchResultEditor(); |
237 | 224 | |
238 | | - $sql = |
239 | | - "SELECT COUNT(*) " . |
240 | | - "FROM {$dc}_expression, {$dc}_syntrans "; |
| 225 | + return $editor->view( new IdStack( "words" ), $recordSet ); |
| 226 | + } |
241 | 227 | |
242 | | - if ( $collectionId > 0 ) |
243 | | - $sql .= ", {$dc}_collection_contents "; |
| 228 | + /** |
| 229 | + * Gives the exact number of results (not limited to 100) |
| 230 | + */ |
| 231 | + function searchWordsCount( $text, $collectionId, $languageId ) { |
| 232 | + $dc = wdGetDataSetContext(); |
| 233 | + $dbr = wfGetDB( DB_SLAVE ); |
244 | 234 | |
245 | | - $sql .= |
246 | | - "WHERE {$dc}_expression.expression_id={$dc}_syntrans.expression_id AND {$dc}_syntrans.identical_meaning=1 " . |
247 | | - " AND " . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
248 | | - " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) . |
249 | | - $this->getSpellingRestriction( $text, 'spelling' ); |
| 235 | + $sql = |
| 236 | + "SELECT COUNT(*) " . |
| 237 | + "FROM {$dc}_expression, {$dc}_syntrans "; |
250 | 238 | |
251 | | - if ( $collectionId > 0 ) |
252 | | - $sql .= |
253 | | - " AND {$dc}_collection_contents.member_mid={$dc}_syntrans.defined_meaning_id " . |
254 | | - " AND {$dc}_collection_contents.collection_id=" . $collectionId . |
255 | | - " AND " . getLatestTransactionRestriction( "{$dc}_collection_contents" ); |
| 239 | + if ( $collectionId > 0 ) |
| 240 | + $sql .= ", {$dc}_collection_contents "; |
256 | 241 | |
257 | | - if ( $languageId > 0 ) |
258 | | - $sql .= |
259 | | - " AND {$dc}_expression.language_id=$languageId"; |
| 242 | + $sql .= |
| 243 | + "WHERE {$dc}_expression.expression_id={$dc}_syntrans.expression_id AND {$dc}_syntrans.identical_meaning=1 " . |
| 244 | + " AND " . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
| 245 | + " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) . |
| 246 | + $this->getSpellingRestriction( $text, 'spelling' ); |
260 | 247 | |
261 | | - $queryResult_r = mysql_query( $sql ); |
262 | | - $queryResult_a = mysql_fetch_row( $queryResult_r ); |
263 | | - $queryResultCount = $queryResult_a[0]; |
| 248 | + if ( $collectionId > 0 ) |
| 249 | + $sql .= |
| 250 | + " AND {$dc}_collection_contents.member_mid={$dc}_syntrans.defined_meaning_id " . |
| 251 | + " AND {$dc}_collection_contents.collection_id=" . $collectionId . |
| 252 | + " AND " . getLatestTransactionRestriction( "{$dc}_collection_contents" ); |
264 | 253 | |
265 | | - return $queryResultCount ; |
266 | | - } |
| 254 | + if ( $languageId > 0 ) |
| 255 | + $sql .= |
| 256 | + " AND {$dc}_expression.language_id=$languageId"; |
267 | 257 | |
268 | | - function getWordsSearchResultAsRecordSet( $queryResult ) { |
| 258 | + $queryResult_r = mysql_query( $sql ); |
| 259 | + $queryResult_a = mysql_fetch_row( $queryResult_r ); |
| 260 | + $queryResultCount = $queryResult_a[0]; |
269 | 261 | |
270 | | - $o = OmegaWikiAttributes::getInstance(); |
| 262 | + return $queryResultCount ; |
| 263 | + } |
271 | 264 | |
272 | | - $dbr = wfGetDB( DB_SLAVE ); |
273 | | - $recordSet = new ArrayRecordSet( new Structure( $o->definedMeaningId, $this->expressionAttribute, $this->meaningAttribute ), new Structure( $o->definedMeaningId ) ); |
| 265 | + function getWordsSearchResultAsRecordSet( $queryResult ) { |
274 | 266 | |
275 | | - while ( $row = $dbr->fetchObject( $queryResult ) ) { |
276 | | - $expressionRecord = new ArrayRecord( $this->expressionStructure ); |
277 | | - $expressionRecord->setAttributeValue( $this->spellingAttribute, $row->spelling ); |
278 | | - $expressionRecord->setAttributeValue( $this->languageAttribute, $row->language_id ); |
| 267 | + $o = OmegaWikiAttributes::getInstance(); |
279 | 268 | |
280 | | - $meaningRecord = new ArrayRecord( $this->meaningStructure ); |
281 | | - $meaningRecord->setAttributeValue( $this->definedMeaningAttribute, getDefinedMeaningReferenceRecord( $row->defined_meaning_id ) ); |
282 | | - $meaningRecord->setAttributeValue( $this->definitionAttribute, getDefinedMeaningDefinition( $row->defined_meaning_id ) ); |
| 269 | + $dbr = wfGetDB( DB_SLAVE ); |
| 270 | + $recordSet = new ArrayRecordSet( new Structure( $o->definedMeaningId, $this->expressionAttribute, $this->meaningAttribute ), new Structure( $o->definedMeaningId ) ); |
283 | 271 | |
284 | | - $recordSet->addRecord( array( $row->defined_meaning_id, $expressionRecord, $meaningRecord ) ); |
285 | | - } |
| 272 | + while ( $row = $dbr->fetchObject( $queryResult ) ) { |
| 273 | + $expressionRecord = new ArrayRecord( $this->expressionStructure ); |
| 274 | + $expressionRecord->setAttributeValue( $this->spellingAttribute, $row->spelling ); |
| 275 | + $expressionRecord->setAttributeValue( $this->languageAttribute, $row->language_id ); |
286 | 276 | |
287 | | - return $recordSet; |
| 277 | + $meaningRecord = new ArrayRecord( $this->meaningStructure ); |
| 278 | + $meaningRecord->setAttributeValue( $this->definedMeaningAttribute, getDefinedMeaningReferenceRecord( $row->defined_meaning_id ) ); |
| 279 | + $meaningRecord->setAttributeValue( $this->definitionAttribute, getDefinedMeaningDefinition( $row->defined_meaning_id ) ); |
| 280 | + |
| 281 | + $recordSet->addRecord( array( $row->defined_meaning_id, $expressionRecord, $meaningRecord ) ); |
288 | 282 | } |
289 | 283 | |
290 | | - function getWordsSearchResultEditor() { |
| 284 | + return $recordSet; |
| 285 | + } |
291 | 286 | |
292 | | - $expressionEditor = new RecordTableCellEditor( $this->expressionAttribute ); |
293 | | - $expressionEditor->addEditor( new SpellingEditor( $this->spellingAttribute, new SimplePermissionController( false ), false ) ); |
294 | | - $expressionEditor->addEditor( new LanguageEditor( $this->languageAttribute, new SimplePermissionController( false ), false ) ); |
| 287 | + function getWordsSearchResultEditor() { |
295 | 288 | |
296 | | - $meaningEditor = new RecordTableCellEditor( $this->meaningAttribute ); |
297 | | - $meaningEditor->addEditor( new DefinedMeaningReferenceEditor( $this->definedMeaningAttribute, new SimplePermissionController( false ), false ) ); |
298 | | - $meaningEditor->addEditor( new TextEditor( $this->definitionAttribute, new SimplePermissionController( false ), false, true, 75 ) ); |
| 289 | + $expressionEditor = new RecordTableCellEditor( $this->expressionAttribute ); |
| 290 | + $expressionEditor->addEditor( new SpellingEditor( $this->spellingAttribute, new SimplePermissionController( false ), false ) ); |
| 291 | + $expressionEditor->addEditor( new LanguageEditor( $this->languageAttribute, new SimplePermissionController( false ), false ) ); |
299 | 292 | |
300 | | - $editor = createTableViewer( null ); |
301 | | - $editor->addEditor( $expressionEditor ); |
302 | | - $editor->addEditor( $meaningEditor ); |
| 293 | + $meaningEditor = new RecordTableCellEditor( $this->meaningAttribute ); |
| 294 | + $meaningEditor->addEditor( new DefinedMeaningReferenceEditor( $this->definedMeaningAttribute, new SimplePermissionController( false ), false ) ); |
| 295 | + $meaningEditor->addEditor( new TextEditor( $this->definitionAttribute, new SimplePermissionController( false ), false, true, 75 ) ); |
303 | 296 | |
304 | | - return $editor; |
305 | | - } |
| 297 | + $editor = createTableViewer( null ); |
| 298 | + $editor->addEditor( $expressionEditor ); |
| 299 | + $editor->addEditor( $meaningEditor ); |
306 | 300 | |
307 | | - function searchExternalIdentifiers( $text, $collectionId ) { |
308 | | - $dc = wdGetDataSetContext(); |
309 | | - $dbr = wfGetDB( DB_SLAVE ); |
| 301 | + return $editor; |
| 302 | + } |
310 | 303 | |
311 | | - $sql = |
312 | | - "SELECT " . $this->getPositionSelectColumn( $text, "{$dc}_collection_contents.internal_member_id" ) . " {$dc}_collection_contents.member_mid AS member_mid, {$dc}_collection_contents.internal_member_id AS external_identifier, {$dc}_collection.collection_mid AS collection_mid " . |
313 | | - "FROM {$dc}_collection_contents, {$dc}_collection "; |
| 304 | + function searchExternalIdentifiers( $text, $collectionId ) { |
| 305 | + $dc = wdGetDataSetContext(); |
| 306 | + $dbr = wfGetDB( DB_SLAVE ); |
314 | 307 | |
| 308 | + $sql = |
| 309 | + "SELECT " . $this->getPositionSelectColumn( $text, "{$dc}_collection_contents.internal_member_id" ) . " {$dc}_collection_contents.member_mid AS member_mid, {$dc}_collection_contents.internal_member_id AS external_identifier, {$dc}_collection.collection_mid AS collection_mid " . |
| 310 | + "FROM {$dc}_collection_contents, {$dc}_collection "; |
| 311 | + |
315 | 312 | $sql .= |
316 | | - "WHERE {$dc}_collection.collection_id={$dc}_collection_contents.collection_id " . |
317 | | - " AND " . getLatestTransactionRestriction( "{$dc}_collection" ) . |
318 | | - " AND " . getLatestTransactionRestriction( "{$dc}_collection_contents" ) . |
319 | | - $this->getSpellingRestriction( $text, "{$dc}_collection_contents.internal_member_id" ); |
| 313 | + "WHERE {$dc}_collection.collection_id={$dc}_collection_contents.collection_id " . |
| 314 | + " AND " . getLatestTransactionRestriction( "{$dc}_collection" ) . |
| 315 | + " AND " . getLatestTransactionRestriction( "{$dc}_collection_contents" ) . |
| 316 | + $this->getSpellingRestriction( $text, "{$dc}_collection_contents.internal_member_id" ); |
320 | 317 | |
321 | | - if ( $collectionId > 0 ) |
322 | | - $sql .= |
323 | | - " AND {$dc}_collection.collection_id=$collectionId "; |
324 | | - |
| 318 | + if ( $collectionId > 0 ) |
325 | 319 | $sql .= |
326 | | - " ORDER BY " . $this->getSpellingOrderBy( $text ) . "{$dc}_collection_contents.internal_member_id ASC limit 100"; |
| 320 | + " AND {$dc}_collection.collection_id=$collectionId "; |
327 | 321 | |
328 | | - $queryResult = $dbr->query( $sql ); |
329 | | - $recordSet = $this->getExternalIdentifiersSearchResultAsRecordSet( $queryResult ); |
330 | | - $editor = $this->getExternalIdentifiersSearchResultEditor(); |
| 322 | + $sql .= |
| 323 | + " ORDER BY " . $this->getSpellingOrderBy( $text ) . "{$dc}_collection_contents.internal_member_id ASC limit 100"; |
331 | 324 | |
332 | | - return $editor->view( new IdStack( "external-identifiers" ), $recordSet ); |
333 | | - } |
| 325 | + $queryResult = $dbr->query( $sql ); |
| 326 | + $recordSet = $this->getExternalIdentifiersSearchResultAsRecordSet( $queryResult ); |
| 327 | + $editor = $this->getExternalIdentifiersSearchResultEditor(); |
334 | 328 | |
335 | | - function getExternalIdentifiersSearchResultAsRecordSet( $queryResult ) { |
336 | | - $dbr = wfGetDB( DB_SLAVE ); |
| 329 | + return $editor->view( new IdStack( "external-identifiers" ), $recordSet ); |
| 330 | + } |
337 | 331 | |
338 | | - $externalIdentifierMatchStructure = new Structure( $this->externalIdentifierAttribute, $this->collectionAttribute, $this->collectionMemberAttribute ); |
339 | | - $recordSet = new ArrayRecordSet( $externalIdentifierMatchStructure, new Structure( $this->externalIdentifierAttribute ) ); |
| 332 | + function getExternalIdentifiersSearchResultAsRecordSet( $queryResult ) { |
| 333 | + $dbr = wfGetDB( DB_SLAVE ); |
340 | 334 | |
341 | | - while ( $row = $dbr->fetchObject( $queryResult ) ) { |
342 | | - $record = new ArrayRecord( $this->externalIdentifierMatchStructure ); |
343 | | - $record->setAttributeValue( $this->externalIdentifierAttribute, $row->external_identifier ); |
344 | | - $record->setAttributeValue( $this->collectionAttribute, $row->collection_mid ); |
345 | | - $record->setAttributeValue( $this->collectionMemberAttribute, $row->member_mid ); |
| 335 | + $externalIdentifierMatchStructure = new Structure( $this->externalIdentifierAttribute, $this->collectionAttribute, $this->collectionMemberAttribute ); |
| 336 | + $recordSet = new ArrayRecordSet( $externalIdentifierMatchStructure, new Structure( $this->externalIdentifierAttribute ) ); |
346 | 337 | |
347 | | - $recordSet->add( $record ); |
348 | | - } |
| 338 | + while ( $row = $dbr->fetchObject( $queryResult ) ) { |
| 339 | + $record = new ArrayRecord( $this->externalIdentifierMatchStructure ); |
| 340 | + $record->setAttributeValue( $this->externalIdentifierAttribute, $row->external_identifier ); |
| 341 | + $record->setAttributeValue( $this->collectionAttribute, $row->collection_mid ); |
| 342 | + $record->setAttributeValue( $this->collectionMemberAttribute, $row->member_mid ); |
349 | 343 | |
350 | | - expandDefinedMeaningReferencesInRecordSet( $recordSet, array( $this->collectionAttribute, $this->collectionMemberAttribute ) ); |
351 | | - |
352 | | - return $recordSet; |
| 344 | + $recordSet->add( $record ); |
353 | 345 | } |
354 | 346 | |
355 | | - function getExternalIdentifiersSearchResultEditor() { |
356 | | - $editor = createTableViewer( null ); |
357 | | - $editor->addEditor( createShortTextViewer( $this->externalIdentifierAttribute ) ); |
358 | | - $editor->addEditor( createDefinedMeaningReferenceViewer( $this->collectionMemberAttribute ) ); |
359 | | - $editor->addEditor( createDefinedMeaningReferenceViewer( $this->collectionAttribute ) ); |
| 347 | + expandDefinedMeaningReferencesInRecordSet( $recordSet, array( $this->collectionAttribute, $this->collectionMemberAttribute ) ); |
360 | 348 | |
361 | | - return $editor; |
362 | | - } |
| 349 | + return $recordSet; |
363 | 350 | } |
364 | 351 | |
365 | | - SpecialPage::addPage( new SpecialDatasearch() ); |
| 352 | + function getExternalIdentifiersSearchResultEditor() { |
| 353 | + $editor = createTableViewer( null ); |
| 354 | + $editor->addEditor( createShortTextViewer( $this->externalIdentifierAttribute ) ); |
| 355 | + $editor->addEditor( createDefinedMeaningReferenceViewer( $this->collectionMemberAttribute ) ); |
| 356 | + $editor->addEditor( createDefinedMeaningReferenceViewer( $this->collectionAttribute ) ); |
| 357 | + |
| 358 | + return $editor; |
| 359 | + } |
366 | 360 | } |
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialImportLangNames.php |
— | — | @@ -1,163 +1,155 @@ |
2 | 2 | <?php |
3 | | - if ( !defined( 'MEDIAWIKI' ) ) die(); |
| 3 | +if ( !defined( 'MEDIAWIKI' ) ) die(); |
4 | 4 | |
5 | | - require_once( "Wikidata.php" ); |
6 | | - $wgGroupPermissions['bureaucrat']['languagenames'] = true; |
7 | | - $wgAvailableRights[] = 'languagenames'; |
| 5 | +require_once( "Wikidata.php" ); |
8 | 6 | |
9 | | - $wgExtensionFunctions[] = 'wfSpecialImportLangNames'; |
10 | | - function wfSpecialImportLangNames() { |
11 | | - class SpecialImportLangNames extends SpecialPage { |
12 | | - function SpecialImportLangNames() { |
13 | | - parent::__construct( 'ImportLangNames' ); |
14 | | - } |
| 7 | +class SpecialImportLangNames extends SpecialPage { |
| 8 | + function SpecialImportLangNames() { |
| 9 | + parent::__construct( 'ImportLangNames' ); |
| 10 | + } |
15 | 11 | |
16 | | - function execute( $par ) { |
17 | | - global $wgOut, $wgUser; |
18 | | - // These operations should always be on the community database. |
19 | | - $dc = "uw"; |
20 | | - require_once( 'Transaction.php' ); |
| 12 | + function execute( $par ) { |
| 13 | + global $wgOut, $wgUser; |
| 14 | + // These operations should always be on the community database. |
| 15 | + $dc = "uw"; |
| 16 | + require_once( 'Transaction.php' ); |
21 | 17 | |
22 | | - $wgOut->setPageTitle( wfMsg( 'importlangnames_title' ) ); |
| 18 | + $wgOut->setPageTitle( wfMsg( 'importlangnames_title' ) ); |
23 | 19 | |
24 | | - if ( !$wgUser->isAllowed( 'languagenames' ) ) { |
25 | | - $wgOut->addHTML( wfMsg( 'importlangnames_not_allowed' ) ); |
26 | | - return false; |
27 | | - } |
| 20 | + if ( !$wgUser->isAllowed( 'languagenames' ) ) { |
| 21 | + $wgOut->addHTML( wfMsg( 'importlangnames_not_allowed' ) ); |
| 22 | + return false; |
| 23 | + } |
28 | 24 | |
29 | | - $dbr = wfGetDB( DB_MASTER ); |
| 25 | + $dbr = wfGetDB( DB_MASTER ); |
30 | 26 | |
31 | | - /* Get collection ID for "ISO 639-3 codes" collection. */ |
32 | | - $sql = "SELECT collection_id FROM {$dc}_collection" . |
33 | | - " JOIN {$dc}_defined_meaning ON defined_meaning_id = collection_mid" . |
34 | | - " JOIN {$dc}_expression ON" . |
35 | | - " {$dc}_defined_meaning.expression_id = {$dc}_expression.expression_id" . |
36 | | - ' WHERE spelling LIKE "ISO 639-3 codes"' . |
37 | | - ' AND ' . getLatestTransactionRestriction( "{$dc}_collection" ) . |
38 | | - ' LIMIT 1'; |
39 | | - $collection_id_res = $dbr->query( $sql ); |
40 | | - $collection_id = $this->fetchResult( $dbr->fetchRow( $collection_id_res ) ); |
| 27 | + /* Get collection ID for "ISO 639-3 codes" collection. */ |
| 28 | + $sql = "SELECT collection_id FROM {$dc}_collection" . |
| 29 | + " JOIN {$dc}_defined_meaning ON defined_meaning_id = collection_mid" . |
| 30 | + " JOIN {$dc}_expression ON" . |
| 31 | + " {$dc}_defined_meaning.expression_id = {$dc}_expression.expression_id" . |
| 32 | + ' WHERE spelling LIKE "ISO 639-3 codes"' . |
| 33 | + ' AND ' . getLatestTransactionRestriction( "{$dc}_collection" ) . |
| 34 | + ' LIMIT 1'; |
| 35 | + $collection_id_res = $dbr->query( $sql ); |
| 36 | + $collection_id = $this->fetchResult( $dbr->fetchRow( $collection_id_res ) ); |
41 | 37 | |
42 | | - /* Get defined meaning IDs and ISO codes for languages in collection. */ |
43 | | - $sql = "SELECT member_mid,internal_member_id FROM {$dc}_collection_contents" . |
44 | | - ' WHERE collection_id = ' . $collection_id . |
45 | | - ' AND ' . getLatestTransactionRestriction( "{$dc}_collection_contents" ); |
46 | | - $lang_res = $dbr->query( $sql ); |
47 | | - $editable = ''; |
48 | | - $first = true; |
49 | | - while ( $lang_row = $dbr->fetchRow( $lang_res ) ) { |
50 | | - $iso_code = $lang_row['internal_member_id']; |
51 | | - $dm_id = $lang_row['member_mid']; |
52 | | - |
53 | | - /* Get the language ID for the current language. */ |
54 | | - $sql = 'SELECT language_id FROM language' . |
55 | | - ' WHERE iso639_3 LIKE ' . $dbr->addQuotes( $iso_code ) . |
56 | | - ' LIMIT 1'; |
57 | | - $lang_id_res = $dbr->query( $sql ); |
58 | | - if ( $dbr->numRows( $lang_id_res ) ) { |
59 | | - if ( !$first ) |
60 | | - $wgOut->addHTML( '<br />' . "\n" ); |
61 | | - else |
62 | | - $first = false; |
63 | | - $wgOut->addHTML( wfMsg( 'importlangnames_added', $iso_code ) ); |
| 38 | + /* Get defined meaning IDs and ISO codes for languages in collection. */ |
| 39 | + $sql = "SELECT member_mid,internal_member_id FROM {$dc}_collection_contents" . |
| 40 | + ' WHERE collection_id = ' . $collection_id . |
| 41 | + ' AND ' . getLatestTransactionRestriction( "{$dc}_collection_contents" ); |
| 42 | + $lang_res = $dbr->query( $sql ); |
| 43 | + $editable = ''; |
| 44 | + $first = true; |
| 45 | + while ( $lang_row = $dbr->fetchRow( $lang_res ) ) { |
| 46 | + $iso_code = $lang_row['internal_member_id']; |
| 47 | + $dm_id = $lang_row['member_mid']; |
64 | 48 | |
65 | | - /* Add current language to list of portals/DMs. */ |
66 | | - $sql = "SELECT spelling FROM {$dc}_expression" . |
67 | | - " JOIN {$dc}_defined_meaning ON {$dc}_defined_meaning.expression_id = {$dc}_expression.expression_id" . |
68 | | - ' WHERE defined_meaning_id = ' . $dm_id . |
69 | | - ' LIMIT 1'; |
70 | | - $dm_expr_res = $dbr->query( $sql ); |
71 | | - $dm_expr = $this->fetchResult( $dbr->fetchRow( $dm_expr_res ) ); |
72 | | - if ( $editable != '' ) |
73 | | - $editable .= "\n"; |
74 | | - $editable .= '*[[Portal:' . $iso_code . ']] - [[DefinedMeaning:' . $dm_expr . ' (' . $dm_id . ')]]'; |
75 | | - } |
76 | | - else { |
77 | | - if ( !$first ) |
78 | | - $wgOut->addHTML( '<br />' . "\n" ); |
79 | | - else |
80 | | - $first = false; |
81 | | - $wgOut->addHTML( wfMsg( 'importlangnames_not_found', $iso_code ) ); |
82 | | - continue; |
83 | | - } |
84 | | - $lang_id = $this->fetchResult( $dbr->fetchRow( $lang_id_res ) ); |
| 49 | + /* Get the language ID for the current language. */ |
| 50 | + $sql = 'SELECT language_id FROM language' . |
| 51 | + ' WHERE iso639_3 LIKE ' . $dbr->addQuotes( $iso_code ) . |
| 52 | + ' LIMIT 1'; |
| 53 | + $lang_id_res = $dbr->query( $sql ); |
| 54 | + if ( $dbr->numRows( $lang_id_res ) ) { |
| 55 | + if ( !$first ) |
| 56 | + $wgOut->addHTML( '<br />' . "\n" ); |
| 57 | + else |
| 58 | + $first = false; |
| 59 | + $wgOut->addHTML( wfMsg( 'importlangnames_added', $iso_code ) ); |
85 | 60 | |
86 | | - /* Delete all language names that match current language ID. */ |
87 | | - $sql = 'DELETE FROM language_names' . |
88 | | - ' WHERE language_id = ' . $lang_id; |
89 | | - $dbr->query( $sql ); |
90 | | - |
91 | | - /* Get syntrans expressions for names of language and IDs for the languages the names are in. */ |
92 | | - $sql = "SELECT spelling,language_id FROM {$dc}_expression" . |
93 | | - " JOIN {$dc}_syntrans" . |
94 | | - " ON {$dc}_expression.expression_id = {$dc}_syntrans.expression_id" . |
95 | | - ' WHERE defined_meaning_id = ' . $dm_id . |
96 | | - ' AND ' . getLatestTransactionRestriction( "{$dc}_expression" ) . |
97 | | - ' AND ' . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
98 | | - ' GROUP BY language_id ORDER BY NULL'; |
99 | | - $syntrans_res = $dbr->query( $sql ); |
100 | | - while ( $syntrans_row = $dbr->fetchRow( $syntrans_res ) ) { |
101 | | - $sql = 'INSERT INTO language_names' . |
102 | | - ' (`language_id`,`name_language_id`,`language_name`)' . |
103 | | - ' VALUES(' . $lang_id . ', ' . |
104 | | - $syntrans_row['language_id'] . ', ' . |
105 | | - $dbr->addQuotes( $syntrans_row['spelling'] ) . ')'; |
106 | | - $dbr->query( $sql ); |
107 | | - } |
108 | | - } |
109 | | - $this->addDMsListToPage( $editable, 'Editable_languages' ); |
| 61 | + /* Add current language to list of portals/DMs. */ |
| 62 | + $sql = "SELECT spelling FROM {$dc}_expression" . |
| 63 | + " JOIN {$dc}_defined_meaning ON {$dc}_defined_meaning.expression_id = {$dc}_expression.expression_id" . |
| 64 | + ' WHERE defined_meaning_id = ' . $dm_id . |
| 65 | + ' LIMIT 1'; |
| 66 | + $dm_expr_res = $dbr->query( $sql ); |
| 67 | + $dm_expr = $this->fetchResult( $dbr->fetchRow( $dm_expr_res ) ); |
| 68 | + if ( $editable != '' ) |
| 69 | + $editable .= "\n"; |
| 70 | + $editable .= '*[[Portal:' . $iso_code . ']] - [[DefinedMeaning:' . $dm_expr . ' (' . $dm_id . ')]]'; |
110 | 71 | } |
| 72 | + else { |
| 73 | + if ( !$first ) |
| 74 | + $wgOut->addHTML( '<br />' . "\n" ); |
| 75 | + else |
| 76 | + $first = false; |
| 77 | + $wgOut->addHTML( wfMsg( 'importlangnames_not_found', $iso_code ) ); |
| 78 | + continue; |
| 79 | + } |
| 80 | + $lang_id = $this->fetchResult( $dbr->fetchRow( $lang_id_res ) ); |
111 | 81 | |
112 | | - /* XXX: This is probably NOT the proper way to do this. It should be refactored. */ |
113 | | - function addDMsListToPage( $content, $page ) { |
114 | | - $dbr = wfGetDB( DB_MASTER ); |
| 82 | + /* Delete all language names that match current language ID. */ |
| 83 | + $sql = 'DELETE FROM language_names' . |
| 84 | + ' WHERE language_id = ' . $lang_id; |
| 85 | + $dbr->query( $sql ); |
115 | 86 | |
116 | | - /* Get ID of the page we want to put the list on. */ |
117 | | - $sql = 'SELECT page_id FROM page' . |
118 | | - ' WHERE page_title LIKE ' . $dbr->addQuotes( $page ) . |
119 | | - ' LIMIT 1'; |
120 | | - $page_res = $dbr->query( $sql ); |
121 | | - $page_id = $this->fetchResult( $dbr->fetchRow( $page_res ) ); |
| 87 | + /* Get syntrans expressions for names of language and IDs for the languages the names are in. */ |
| 88 | + $sql = "SELECT spelling,language_id FROM {$dc}_expression" . |
| 89 | + " JOIN {$dc}_syntrans" . |
| 90 | + " ON {$dc}_expression.expression_id = {$dc}_syntrans.expression_id" . |
| 91 | + ' WHERE defined_meaning_id = ' . $dm_id . |
| 92 | + ' AND ' . getLatestTransactionRestriction( "{$dc}_expression" ) . |
| 93 | + ' AND ' . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
| 94 | + ' GROUP BY language_id ORDER BY NULL'; |
| 95 | + $syntrans_res = $dbr->query( $sql ); |
| 96 | + while ( $syntrans_row = $dbr->fetchRow( $syntrans_res ) ) { |
| 97 | + $sql = 'INSERT INTO language_names' . |
| 98 | + ' (`language_id`,`name_language_id`,`language_name`)' . |
| 99 | + ' VALUES(' . $lang_id . ', ' . |
| 100 | + $syntrans_row['language_id'] . ', ' . |
| 101 | + $dbr->addQuotes( $syntrans_row['spelling'] ) . ')'; |
| 102 | + $dbr->query( $sql ); |
| 103 | + } |
| 104 | + } |
| 105 | + $this->addDMsListToPage( $editable, 'Editable_languages' ); |
| 106 | + } |
122 | 107 | |
123 | | - /* Don't do anything if the old content is the same as the new. */ |
124 | | - $sql = 'SELECT old_text FROM text' . |
125 | | - ' JOIN revision ON rev_text_id = old_id' . |
126 | | - ' WHERE rev_page = ' . $page_id . |
127 | | - ' LIMIT 1'; |
128 | | - $current_res = $dbr->query( $sql ); |
129 | | - $current = $this->fetchResult( $dbr->fetchRow( $current_res ) ); |
130 | | - if ( $content == $current ) |
131 | | - return; |
| 108 | + /* XXX: This is probably NOT the proper way to do this. It should be refactored. */ |
| 109 | + function addDMsListToPage( $content, $page ) { |
| 110 | + $dbr = wfGetDB( DB_MASTER ); |
132 | 111 | |
133 | | - /* Insert new text and grab new row ID. */ |
134 | | - $sql = 'INSERT INTO text (`old_text`,`old_flags`)' . |
135 | | - ' VALUES(' . $dbr->addQuotes( $content ) . ',' . |
136 | | - $dbr->addQuotes( 'utf-8' ) . ')'; |
137 | | - $dbr->query( $sql ); |
138 | | - $text_id = $dbr->insertId(); |
| 112 | + /* Get ID of the page we want to put the list on. */ |
| 113 | + $sql = 'SELECT page_id FROM page' . |
| 114 | + ' WHERE page_title LIKE ' . $dbr->addQuotes( $page ) . |
| 115 | + ' LIMIT 1'; |
| 116 | + $page_res = $dbr->query( $sql ); |
| 117 | + $page_id = $this->fetchResult( $dbr->fetchRow( $page_res ) ); |
139 | 118 | |
140 | | - /* Add new revision to database and update page entry. */ |
141 | | - $time = wfTimestamp( TS_MW ); |
142 | | - $sql = 'INSERT INTO revision (`rev_page`,`rev_text_id`,' . |
143 | | - '`rev_comment`,`rev_user_text`,`rev_timestamp`)' . |
144 | | - ' VALUES(' . $page_id . ',' . $text_id . ',' . |
145 | | - $dbr->addQuotes( 'Set to latest DefinedMeanings list' ) . |
146 | | - ',' . $dbr->addQuotes( 'ImportLangNames' ) . ',' . $time . ')'; |
147 | | - $dbr->query( $sql ); |
148 | | - $rev_id = $dbr->insertId(); |
149 | | - $sql = 'UPDATE page SET page_latest = ' . $rev_id . ',page_touched = ' . |
150 | | - $time . ',page_is_new = 0,page_len = ' . strlen( $content ) . |
151 | | - ' WHERE page_id = ' . $page_id; |
152 | | - $dbr->query( $sql ); |
153 | | - } |
| 119 | + /* Don't do anything if the old content is the same as the new. */ |
| 120 | + $sql = 'SELECT old_text FROM text' . |
| 121 | + ' JOIN revision ON rev_text_id = old_id' . |
| 122 | + ' WHERE rev_page = ' . $page_id . |
| 123 | + ' LIMIT 1'; |
| 124 | + $current_res = $dbr->query( $sql ); |
| 125 | + $current = $this->fetchResult( $dbr->fetchRow( $current_res ) ); |
| 126 | + if ( $content == $current ) |
| 127 | + return; |
154 | 128 | |
155 | | - /* Return first field in row. */ |
156 | | - function fetchResult( $row ) { |
157 | | - return $row[0]; |
158 | | - } |
| 129 | + /* Insert new text and grab new row ID. */ |
| 130 | + $sql = 'INSERT INTO text (`old_text`,`old_flags`)' . |
| 131 | + ' VALUES(' . $dbr->addQuotes( $content ) . ',' . |
| 132 | + $dbr->addQuotes( 'utf-8' ) . ')'; |
| 133 | + $dbr->query( $sql ); |
| 134 | + $text_id = $dbr->insertId(); |
159 | 135 | |
160 | | - } |
| 136 | + /* Add new revision to database and update page entry. */ |
| 137 | + $time = wfTimestamp( TS_MW ); |
| 138 | + $sql = 'INSERT INTO revision (`rev_page`,`rev_text_id`,' . |
| 139 | + '`rev_comment`,`rev_user_text`,`rev_timestamp`)' . |
| 140 | + ' VALUES(' . $page_id . ',' . $text_id . ',' . |
| 141 | + $dbr->addQuotes( 'Set to latest DefinedMeanings list' ) . |
| 142 | + ',' . $dbr->addQuotes( 'ImportLangNames' ) . ',' . $time . ')'; |
| 143 | + $dbr->query( $sql ); |
| 144 | + $rev_id = $dbr->insertId(); |
| 145 | + $sql = 'UPDATE page SET page_latest = ' . $rev_id . ',page_touched = ' . |
| 146 | + $time . ',page_is_new = 0,page_len = ' . strlen( $content ) . |
| 147 | + ' WHERE page_id = ' . $page_id; |
| 148 | + $dbr->query( $sql ); |
| 149 | + } |
161 | 150 | |
162 | | - SpecialPage::addPage( new SpecialImportLangNames ); |
| 151 | + /* Return first field in row. */ |
| 152 | + function fetchResult( $row ) { |
| 153 | + return $row[0]; |
163 | 154 | } |
164 | 155 | |
| 156 | +} |
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialAddCollection.php |
— | — | @@ -1,60 +1,52 @@ |
2 | 2 | <?php |
3 | | - if ( !defined( 'MEDIAWIKI' ) ) die(); |
| 3 | +if ( !defined( 'MEDIAWIKI' ) ) die(); |
4 | 4 | |
5 | | - require_once( "WikiDataAPI.php" ); // for bootstrapCollection |
6 | | - require_once( "Utilities.php" ); |
7 | | - |
8 | | - $wgAvailableRights[] = 'addcollection'; |
9 | | - $wgGroupPermissions['bureaucrat']['addcollection'] = true; |
10 | | - $wgExtensionFunctions[] = 'wfSpecialAddCollection'; |
| 5 | +require_once( "WikiDataAPI.php" ); // for bootstrapCollection |
| 6 | +require_once( "Utilities.php" ); |
11 | 7 | |
12 | | - function wfSpecialAddCollection() { |
13 | | - class SpecialAddCollection extends SpecialPage { |
14 | | - function SpecialAddCollection() { |
15 | | - parent::__construct( 'AddCollection' ); |
16 | | - } |
| 8 | +class SpecialAddCollection extends SpecialPage { |
| 9 | + function SpecialAddCollection() { |
| 10 | + parent::__construct( 'AddCollection' ); |
| 11 | + } |
17 | 12 | |
18 | | - function execute( $par ) { |
| 13 | + function execute( $par ) { |
19 | 14 | |
20 | | - global $wgOut, $wgUser, $wgRequest; |
| 15 | + global $wgOut, $wgUser, $wgRequest; |
21 | 16 | |
22 | | - $wgOut->setPageTitle( 'Add Collection' ); |
| 17 | + $wgOut->setPageTitle( 'Add Collection' ); |
23 | 18 | |
24 | | - if ( !$wgUser->isAllowed( 'addcollection' ) ) { |
25 | | - $wgOut->addHTML( 'You do not have permission to add a collection.' ); |
26 | | - return false; |
27 | | - } |
| 19 | + if ( !$wgUser->isAllowed( 'addcollection' ) ) { |
| 20 | + $wgOut->addHTML( 'You do not have permission to add a collection.' ); |
| 21 | + return false; |
| 22 | + } |
28 | 23 | |
29 | | - $dbr = wfGetDB( DB_MASTER ); |
| 24 | + $dbr = wfGetDB( DB_MASTER ); |
30 | 25 | |
31 | | - if ( $wgRequest->getText( 'collection' ) ) { |
32 | | - require_once( 'WikiDataAPI.php' ); |
33 | | - require_once( 'Transaction.php' ); |
| 26 | + if ( $wgRequest->getText( 'collection' ) ) { |
| 27 | + require_once( 'WikiDataAPI.php' ); |
| 28 | + require_once( 'Transaction.php' ); |
34 | 29 | |
35 | | - $dc = $wgRequest->getText( 'dataset' ); |
36 | | - $collectionName = $wgRequest->getText( 'collection' ); |
37 | | - startNewTransaction( $wgUser->getID(), wfGetIP(), 'Add collection ' . $collectionName ); |
38 | | - bootstrapCollection( $collectionName, $wgRequest->getText( 'language' ), $wgRequest->getText( 'type' ), $dc ); |
39 | | - $wgOut->addHTML( wfMsg( 'ow_collection_added', $collectionName ) . "<br />" ); |
40 | | - } |
41 | | - $datasets = wdGetDatasets(); |
42 | | - $datasetarray[''] = wfMsgSc( "none_selected" ); |
43 | | - foreach ( $datasets as $datasetid => $dataset ) { |
44 | | - $datasetarray[$datasetid] = $dataset->fetchName(); |
45 | | - } |
46 | | - |
47 | | - $wgOut->addHTML( getOptionPanel( |
48 | | - array( |
49 | | - 'Collection name:' => getTextBox( 'collection' ), |
50 | | - 'Language of name:' => getSuggest( 'language', 'language' ), |
51 | | - 'Collection type:' => getSelect( 'type', array( '' => 'None', 'RELT' => 'RELT', 'LEVL' => 'LEVL', 'CLAS' => 'CLAS', 'MAPP' => 'MAPP' ) ), |
52 | | - 'Dataset:' => getSelect( 'dataset', $datasetarray ) |
53 | | - ), |
54 | | - '', array( 'create' => wfMsg( 'ow_create' ) ) |
55 | | - ) ); |
56 | | - } |
| 30 | + $dc = $wgRequest->getText( 'dataset' ); |
| 31 | + $collectionName = $wgRequest->getText( 'collection' ); |
| 32 | + startNewTransaction( $wgUser->getID(), wfGetIP(), 'Add collection ' . $collectionName ); |
| 33 | + bootstrapCollection( $collectionName, $wgRequest->getText( 'language' ), $wgRequest->getText( 'type' ), $dc ); |
| 34 | + $wgOut->addHTML( wfMsg( 'ow_collection_added', $collectionName ) . "<br />" ); |
57 | 35 | } |
| 36 | + $datasets = wdGetDatasets(); |
| 37 | + $datasetarray[''] = wfMsgSc( "none_selected" ); |
| 38 | + foreach ( $datasets as $datasetid => $dataset ) { |
| 39 | + $datasetarray[$datasetid] = $dataset->fetchName(); |
| 40 | + } |
58 | 41 | |
59 | | - SpecialPage::addPage( new SpecialAddCollection ); |
| 42 | + $wgOut->addHTML( getOptionPanel( |
| 43 | + array( |
| 44 | + 'Collection name:' => getTextBox( 'collection' ), |
| 45 | + 'Language of name:' => getSuggest( 'language', 'language' ), |
| 46 | + 'Collection type:' => getSelect( 'type', array( '' => 'None', 'RELT' => 'RELT', 'LEVL' => 'LEVL', 'CLAS' => 'CLAS', 'MAPP' => 'MAPP' ) ), |
| 47 | + 'Dataset:' => getSelect( 'dataset', $datasetarray ) |
| 48 | + ), |
| 49 | + '', array( 'create' => wfMsg( 'ow_create' ) ) |
| 50 | + ) ); |
60 | 51 | } |
| 52 | +} |
61 | 53 | |
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialNeedsTranslation.php |
— | — | @@ -1,156 +1,150 @@ |
2 | 2 | <?php |
3 | | - if ( !defined( 'MEDIAWIKI' ) ) die(); |
| 3 | +if ( !defined( 'MEDIAWIKI' ) ) die(); |
4 | 4 | |
5 | | - $wgExtensionFunctions[] = 'wfSpecialNeedsTranslation'; |
| 5 | +require_once( "Wikidata.php" ); |
6 | 6 | |
7 | | - require_once( "Wikidata.php" ); |
| 7 | +class SpecialNeedsTranslation extends SpecialPage { |
| 8 | + function __construct() { |
| 9 | + parent::__construct( 'NeedsTranslation' ); |
| 10 | + } |
8 | 11 | |
9 | | - function wfSpecialNeedsTranslation() { |
10 | | - class SpecialNeedsTranslation extends SpecialPage { |
11 | | - function SpecialNeedsTranslation() { |
12 | | - parent::__construct( 'NeedsTranslation' ); |
13 | | - } |
| 12 | + function execute( $par ) { |
| 13 | + global $wgOut, $wgRequest; |
14 | 14 | |
15 | | - function execute( $par ) { |
16 | | - global $wgOut, $wgRequest; |
| 15 | + require_once( "forms.php" ); |
| 16 | + require_once( "type.php" ); |
| 17 | + require_once( "OmegaWikiAttributes.php" ); |
| 18 | + require_once( "ViewInformation.php" ); |
17 | 19 | |
18 | | - require_once( "forms.php" ); |
19 | | - require_once( "type.php" ); |
20 | | - require_once( "OmegaWikiAttributes.php" ); |
21 | | - require_once( "ViewInformation.php" ); |
| 20 | + initializeOmegaWikiAttributes( new ViewInformation() ); |
| 21 | + $wgOut->setPageTitle( wfMsg( 'ow_needs_xlation_title' ) ); |
22 | 22 | |
23 | | - initializeOmegaWikiAttributes( new ViewInformation() ); |
24 | | - $wgOut->setPageTitle( wfMsg( 'ow_needs_xlation_title' ) ); |
25 | | - |
26 | | - $destinationLanguageId = array_key_exists( 'to-lang', $_GET ) ? $_GET['to-lang']:''; |
27 | | - $collectionId = array_key_exists( 'collection', $_GET ) ? $_GET['collection'] : ''; |
28 | | - $sourceLanguageId = array_key_exists( 'from-lang', $_GET ) ? $_GET['from-lang'] : ''; |
| 23 | + $destinationLanguageId = array_key_exists( 'to-lang', $_GET ) ? $_GET['to-lang']:''; |
| 24 | + $collectionId = array_key_exists( 'collection', $_GET ) ? $_GET['collection'] : ''; |
| 25 | + $sourceLanguageId = array_key_exists( 'from-lang', $_GET ) ? $_GET['from-lang'] : ''; |
29 | 26 | |
30 | | - $wgOut->addHTML( getOptionPanel( |
31 | | - array( |
32 | | - wfMsg( 'ow_needs_xlation_dest_lang' ) => getSuggest( 'to-lang', 'language', array(), $destinationLanguageId, languageIdAsText( $destinationLanguageId ) ), |
33 | | - wfMsg( 'ow_needs_xlation_source_lang' ) => getSuggest( 'from-lang', 'language', array(), $sourceLanguageId, languageIdAsText( $sourceLanguageId ) ), |
34 | | - wfMsg( 'ow_Collection_colon' ) => getSuggest( 'collection', 'collection', array(), $collectionId, collectionIdAsText( $collectionId ) ) |
35 | | - ) |
36 | | - ) ); |
| 27 | + $wgOut->addHTML( getOptionPanel( |
| 28 | + array( |
| 29 | + wfMsg( 'ow_needs_xlation_dest_lang' ) => getSuggest( 'to-lang', 'language', array(), $destinationLanguageId, languageIdAsText( $destinationLanguageId ) ), |
| 30 | + wfMsg( 'ow_needs_xlation_source_lang' ) => getSuggest( 'from-lang', 'language', array(), $sourceLanguageId, languageIdAsText( $sourceLanguageId ) ), |
| 31 | + wfMsg( 'ow_Collection_colon' ) => getSuggest( 'collection', 'collection', array(), $collectionId, collectionIdAsText( $collectionId ) ) |
| 32 | + ) |
| 33 | + ) ); |
37 | 34 | |
38 | | - if ( $destinationLanguageId == '' ) |
39 | | - $wgOut->addHTML( '<p>' . wfMsg( 'ow_needs_xlation_no_dest_lang' ) . '</p>' ); |
40 | | - else |
41 | | - $this->showExpressionsNeedingTranslation( $sourceLanguageId, $destinationLanguageId, $collectionId ); |
42 | | - } |
| 35 | + if ( $destinationLanguageId == '' ) |
| 36 | + $wgOut->addHTML( '<p>' . wfMsg( 'ow_needs_xlation_no_dest_lang' ) . '</p>' ); |
| 37 | + else |
| 38 | + $this->showExpressionsNeedingTranslation( $sourceLanguageId, $destinationLanguageId, $collectionId ); |
| 39 | + } |
43 | 40 | |
44 | | - protected function showExpressionsNeedingTranslation( $sourceLanguageId, $destinationLanguageId, $collectionId ) { |
| 41 | + protected function showExpressionsNeedingTranslation( $sourceLanguageId, $destinationLanguageId, $collectionId ) { |
45 | 42 | |
46 | | - $o = OmegaWikiAttributes::getInstance(); |
| 43 | + $o = OmegaWikiAttributes::getInstance(); |
47 | 44 | |
48 | | - $dc = wdGetDataSetContext(); |
49 | | - require_once( "Transaction.php" ); |
50 | | - require_once( "OmegaWikiAttributes.php" ); |
51 | | - require_once( "RecordSet.php" ); |
52 | | - require_once( "Editor.php" ); |
53 | | - require_once( "WikiDataAPI.php" ); |
| 45 | + $dc = wdGetDataSetContext(); |
| 46 | + require_once( "Transaction.php" ); |
| 47 | + require_once( "OmegaWikiAttributes.php" ); |
| 48 | + require_once( "RecordSet.php" ); |
| 49 | + require_once( "Editor.php" ); |
| 50 | + require_once( "WikiDataAPI.php" ); |
54 | 51 | |
55 | | - $dbr = wfGetDB( DB_SLAVE ); |
| 52 | + $dbr = wfGetDB( DB_SLAVE ); |
56 | 53 | |
57 | | - $sqlcount = 'SELECT COUNT(*)' . |
58 | | - " FROM ({$dc}_syntrans source_syntrans, {$dc}_expression source_expression)"; |
| 54 | + $sqlcount = 'SELECT COUNT(*)' . |
| 55 | + " FROM ({$dc}_syntrans source_syntrans, {$dc}_expression source_expression)"; |
59 | 56 | |
60 | | - if ( $collectionId != '' ) |
61 | | - $sqlcount .= " JOIN {$dc}_collection_contents ON source_syntrans.defined_meaning_id = member_mid"; |
| 57 | + if ( $collectionId != '' ) |
| 58 | + $sqlcount .= " JOIN {$dc}_collection_contents ON source_syntrans.defined_meaning_id = member_mid"; |
62 | 59 | |
63 | | - $sqlcount .= ' WHERE source_syntrans.expression_id = source_expression.expression_id'; |
| 60 | + $sqlcount .= ' WHERE source_syntrans.expression_id = source_expression.expression_id'; |
64 | 61 | |
65 | | - if ( $sourceLanguageId != '' ) |
66 | | - $sqlcount .= ' AND source_expression.language_id = ' . $sourceLanguageId; |
67 | | - if ( $collectionId != '' ) |
68 | | - $sqlcount .= " AND {$dc}_collection_contents.collection_id = " . $collectionId . |
69 | | - ' AND ' . getLatestTransactionRestriction( "{$dc}_collection_contents" ); |
| 62 | + if ( $sourceLanguageId != '' ) |
| 63 | + $sqlcount .= ' AND source_expression.language_id = ' . $sourceLanguageId; |
| 64 | + if ( $collectionId != '' ) |
| 65 | + $sqlcount .= " AND {$dc}_collection_contents.collection_id = " . $collectionId . |
| 66 | + ' AND ' . getLatestTransactionRestriction( "{$dc}_collection_contents" ); |
70 | 67 | |
71 | | - $sqlcount .= ' AND NOT EXISTS (' . |
72 | | - " SELECT * FROM {$dc}_syntrans destination_syntrans, {$dc}_expression destination_expression" . |
73 | | - ' WHERE destination_syntrans.expression_id = destination_expression.expression_id AND destination_expression.language_id = ' . $destinationLanguageId . |
74 | | - ' AND source_syntrans.defined_meaning_id = destination_syntrans.defined_meaning_id' . |
75 | | - ' AND ' . getLatestTransactionRestriction( 'destination_syntrans' ) . |
76 | | - ' AND ' . getLatestTransactionRestriction( 'destination_expression' ) . |
77 | | - ')' . |
78 | | - ' AND ' . getLatestTransactionRestriction( 'source_syntrans' ) . |
79 | | - ' AND ' . getLatestTransactionRestriction( 'source_expression' ) ; |
| 68 | + $sqlcount .= ' AND NOT EXISTS (' . |
| 69 | + " SELECT * FROM {$dc}_syntrans destination_syntrans, {$dc}_expression destination_expression" . |
| 70 | + ' WHERE destination_syntrans.expression_id = destination_expression.expression_id AND destination_expression.language_id = ' . $destinationLanguageId . |
| 71 | + ' AND source_syntrans.defined_meaning_id = destination_syntrans.defined_meaning_id' . |
| 72 | + ' AND ' . getLatestTransactionRestriction( 'destination_syntrans' ) . |
| 73 | + ' AND ' . getLatestTransactionRestriction( 'destination_expression' ) . |
| 74 | + ')' . |
| 75 | + ' AND ' . getLatestTransactionRestriction( 'source_syntrans' ) . |
| 76 | + ' AND ' . getLatestTransactionRestriction( 'source_expression' ) ; |
80 | 77 | |
81 | | - $queryResultCount_r = mysql_query( $sqlcount ); |
82 | | - $queryResultCount_a = mysql_fetch_row( $queryResultCount_r ); |
83 | | - $queryResultCount = $queryResultCount_a[0]; |
84 | | - $nbshown = min ( 100, $queryResultCount ) ; |
| 78 | + $queryResultCount_r = mysql_query( $sqlcount ); |
| 79 | + $queryResultCount_a = mysql_fetch_row( $queryResultCount_r ); |
| 80 | + $queryResultCount = $queryResultCount_a[0]; |
| 81 | + $nbshown = min ( 100, $queryResultCount ) ; |
85 | 82 | |
86 | 83 | |
87 | | - $sql = 'SELECT source_expression.expression_id AS source_expression_id, source_expression.language_id AS source_language_id, source_expression.spelling AS source_spelling, source_syntrans.defined_meaning_id AS source_defined_meaning_id' . |
88 | | - " FROM ({$dc}_syntrans source_syntrans, {$dc}_expression source_expression)"; |
| 84 | + $sql = 'SELECT source_expression.expression_id AS source_expression_id, source_expression.language_id AS source_language_id, source_expression.spelling AS source_spelling, source_syntrans.defined_meaning_id AS source_defined_meaning_id' . |
| 85 | + " FROM ({$dc}_syntrans source_syntrans, {$dc}_expression source_expression)"; |
89 | 86 | |
90 | | - if ( $collectionId != '' ) |
91 | | - $sql .= " JOIN {$dc}_collection_contents ON source_syntrans.defined_meaning_id = member_mid"; |
| 87 | + if ( $collectionId != '' ) |
| 88 | + $sql .= " JOIN {$dc}_collection_contents ON source_syntrans.defined_meaning_id = member_mid"; |
92 | 89 | |
93 | | - $sql .= ' WHERE source_syntrans.expression_id = source_expression.expression_id'; |
| 90 | + $sql .= ' WHERE source_syntrans.expression_id = source_expression.expression_id'; |
94 | 91 | |
95 | | - if ( $sourceLanguageId != '' ) |
96 | | - $sql .= ' AND source_expression.language_id = ' . $sourceLanguageId; |
97 | | - if ( $collectionId != '' ) |
98 | | - $sql .= " AND {$dc}_collection_contents.collection_id = " . $collectionId . |
99 | | - ' AND ' . getLatestTransactionRestriction( "{$dc}_collection_contents" ); |
| 92 | + if ( $sourceLanguageId != '' ) |
| 93 | + $sql .= ' AND source_expression.language_id = ' . $sourceLanguageId; |
| 94 | + if ( $collectionId != '' ) |
| 95 | + $sql .= " AND {$dc}_collection_contents.collection_id = " . $collectionId . |
| 96 | + ' AND ' . getLatestTransactionRestriction( "{$dc}_collection_contents" ); |
100 | 97 | |
101 | | - $sql .= ' AND NOT EXISTS (' . |
102 | | - " SELECT * FROM {$dc}_syntrans destination_syntrans, {$dc}_expression destination_expression" . |
103 | | - ' WHERE destination_syntrans.expression_id = destination_expression.expression_id AND destination_expression.language_id = ' . $destinationLanguageId . |
104 | | - ' AND source_syntrans.defined_meaning_id = destination_syntrans.defined_meaning_id' . |
105 | | - ' AND ' . getLatestTransactionRestriction( 'destination_syntrans' ) . |
106 | | - ' AND ' . getLatestTransactionRestriction( 'destination_expression' ) . |
107 | | - ')' . |
108 | | - ' AND ' . getLatestTransactionRestriction( 'source_syntrans' ) . |
109 | | - ' AND ' . getLatestTransactionRestriction( 'source_expression' ) ; |
| 98 | + $sql .= ' AND NOT EXISTS (' . |
| 99 | + " SELECT * FROM {$dc}_syntrans destination_syntrans, {$dc}_expression destination_expression" . |
| 100 | + ' WHERE destination_syntrans.expression_id = destination_expression.expression_id AND destination_expression.language_id = ' . $destinationLanguageId . |
| 101 | + ' AND source_syntrans.defined_meaning_id = destination_syntrans.defined_meaning_id' . |
| 102 | + ' AND ' . getLatestTransactionRestriction( 'destination_syntrans' ) . |
| 103 | + ' AND ' . getLatestTransactionRestriction( 'destination_expression' ) . |
| 104 | + ')' . |
| 105 | + ' AND ' . getLatestTransactionRestriction( 'source_syntrans' ) . |
| 106 | + ' AND ' . getLatestTransactionRestriction( 'source_expression' ) ; |
110 | 107 | |
111 | | - if ( $queryResultCount > 100 ) { |
112 | | - $startnumber = rand ( 0 , $queryResultCount - 100 ) ; |
113 | | - $sql .= " LIMIT $startnumber,100"; |
114 | | - } else { |
115 | | - $sql .= ' LIMIT 100'; |
116 | | - } |
| 108 | + if ( $queryResultCount > 100 ) { |
| 109 | + $startnumber = rand ( 0 , $queryResultCount - 100 ) ; |
| 110 | + $sql .= " LIMIT $startnumber,100"; |
| 111 | + } else { |
| 112 | + $sql .= ' LIMIT 100'; |
| 113 | + } |
117 | 114 | |
118 | | - $queryResult = $dbr->query( $sql ); |
| 115 | + $queryResult = $dbr->query( $sql ); |
119 | 116 | |
120 | 117 | |
121 | | - $definitionAttribute = new Attribute( "definition", wfMsg( "ow_Definition" ), "definition" ); |
| 118 | + $definitionAttribute = new Attribute( "definition", wfMsg( "ow_Definition" ), "definition" ); |
122 | 119 | |
123 | | - $recordSet = new ArrayRecordSet( new Structure( $o->definedMeaningId, $o->expressionId, $o->expression, $definitionAttribute ), new Structure( $o->definedMeaningId, $o->expressionId ) ); |
| 120 | + $recordSet = new ArrayRecordSet( new Structure( $o->definedMeaningId, $o->expressionId, $o->expression, $definitionAttribute ), new Structure( $o->definedMeaningId, $o->expressionId ) ); |
124 | 121 | |
125 | | - while ( $row = $dbr->fetchObject( $queryResult ) ) { |
126 | | - $expressionRecord = new ArrayRecord( $o->expressionStructure ); |
127 | | - $expressionRecord->language = $row->source_language_id; |
128 | | - $spellingAsLink = definedMeaningReferenceAsLink( $row->source_defined_meaning_id, $row->source_spelling, $row->source_spelling ); |
129 | | - $expressionRecord->spelling = $spellingAsLink ; |
| 122 | + while ( $row = $dbr->fetchObject( $queryResult ) ) { |
| 123 | + $expressionRecord = new ArrayRecord( $o->expressionStructure ); |
| 124 | + $expressionRecord->language = $row->source_language_id; |
| 125 | + $spellingAsLink = definedMeaningReferenceAsLink( $row->source_defined_meaning_id, $row->source_spelling, $row->source_spelling ); |
| 126 | + $expressionRecord->spelling = $spellingAsLink ; |
130 | 127 | |
131 | | - $definition = getDefinedMeaningDefinitionForLanguage( $row->source_defined_meaning_id, $row->source_language_id ) ; |
132 | | - if ( $definition == "" ) { |
133 | | - $definition = getDefinedMeaningDefinition( $row->source_defined_meaning_id ) ; |
134 | | - } |
| 128 | + $definition = getDefinedMeaningDefinitionForLanguage( $row->source_defined_meaning_id, $row->source_language_id ) ; |
| 129 | + if ( $definition == "" ) { |
| 130 | + $definition = getDefinedMeaningDefinition( $row->source_defined_meaning_id ) ; |
| 131 | + } |
135 | 132 | |
136 | | - $recordSet->addRecord( array( $row->source_defined_meaning_id, $row->source_expression_id, $expressionRecord, $definition ) ); |
137 | | - } |
| 133 | + $recordSet->addRecord( array( $row->source_defined_meaning_id, $row->source_expression_id, $expressionRecord, $definition ) ); |
| 134 | + } |
138 | 135 | |
139 | | - $expressionEditor = new RecordTableCellEditor( $o->expression ); |
140 | | - $expressionEditor->addEditor( new LanguageEditor( $o->language, new SimplePermissionController( false ), false ) ); |
141 | | - $expressionEditor->addEditor( new ShortTextNoEscapeEditor( $o->spelling, new SimplePermissionController( false ), false ) ); |
| 136 | + $expressionEditor = new RecordTableCellEditor( $o->expression ); |
| 137 | + $expressionEditor->addEditor( new LanguageEditor( $o->language, new SimplePermissionController( false ), false ) ); |
| 138 | + $expressionEditor->addEditor( new ShortTextNoEscapeEditor( $o->spelling, new SimplePermissionController( false ), false ) ); |
142 | 139 | |
143 | | - $editor = new RecordSetTableEditor( null, new SimplePermissionController( false ), new ShowEditFieldChecker( true ), new AllowAddController( false ), false, false, null ); |
144 | | - $editor->addEditor( $expressionEditor ); |
145 | | - $editor->addEditor( new TextEditor( $definitionAttribute, new SimplePermissionController( false ), false, true, 75 ) ); |
| 140 | + $editor = new RecordSetTableEditor( null, new SimplePermissionController( false ), new ShowEditFieldChecker( true ), new AllowAddController( false ), false, false, null ); |
| 141 | + $editor->addEditor( $expressionEditor ); |
| 142 | + $editor->addEditor( new TextEditor( $definitionAttribute, new SimplePermissionController( false ), false, true, 75 ) ); |
146 | 143 | |
147 | | - global $wgOut; |
| 144 | + global $wgOut; |
148 | 145 | |
149 | | - $wgOut->addHTML( "Showing $nbshown out of $queryResultCount" ) ; |
150 | | - $wgOut->addHTML( $editor->view( new IdStack( "expression" ), $recordSet ) ); |
151 | | - } |
152 | | - } |
153 | | - |
154 | | - SpecialPage::addPage( new SpecialNeedsTranslation ); |
| 146 | + $wgOut->addHTML( "Showing $nbshown out of $queryResultCount" ) ; |
| 147 | + $wgOut->addHTML( $editor->view( new IdStack( "expression" ), $recordSet ) ); |
155 | 148 | } |
| 149 | +} |
156 | 150 | |
157 | 151 | |
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialExportTSV.php |
— | — | @@ -1,272 +1,263 @@ |
2 | 2 | <?php |
3 | 3 | if ( !defined( 'MEDIAWIKI' ) ) die(); |
4 | 4 | |
5 | | - require_once( "WikiDataAPI.php" ); // for bootstrapCollection |
6 | | - require_once( "Utilities.php" ); |
| 5 | +require_once( "WikiDataAPI.php" ); // for bootstrapCollection |
| 6 | +require_once( "Utilities.php" ); |
| 7 | + |
| 8 | +class SpecialExportTSV extends SpecialPage { |
7 | 9 | |
8 | | - $wgGroupPermissions['bureaucrat']['exporttsv'] = true; |
9 | | - $wgAvailableRights[] = 'exporttsv'; |
10 | | - $wgExtensionFunctions[] = 'wfSpecialExportTSV'; |
| 10 | + function __construct() { |
| 11 | + parent::__construct( 'ExportTSV' ); |
| 12 | + } |
11 | 13 | |
12 | | - function wfSpecialExportTSV() { |
13 | | - class SpecialExportTSV extends SpecialPage { |
14 | | - |
15 | | - function SpecialExportTSV() { |
16 | | - parent::__construct( 'ExportTSV' ); |
17 | | - } |
| 14 | + function execute( $par ) { |
18 | 15 | |
19 | | - function execute( $par ) { |
| 16 | + global $wgOut, $wgUser, $wgRequest; |
20 | 17 | |
21 | | - global $wgOut, $wgUser, $wgRequest; |
| 18 | + if ( !$wgUser->isAllowed( 'exporttsv' ) ) { |
| 19 | + $wgOut->addHTML( wfMsg( 'ow_exporttsv_not_allowed' ) ); |
| 20 | + return false; |
| 21 | + } |
| 22 | + |
| 23 | + $dbr = wfGetDB( DB_SLAVE ); |
| 24 | + $dc = wdGetDataSetcontext(); |
| 25 | + |
| 26 | + if ( $wgRequest->getText( 'collection' ) && $wgRequest->getText( 'languages' ) ) { |
| 27 | + // render the tsv file |
22 | 28 | |
23 | | - if ( !$wgUser->isAllowed( 'exporttsv' ) ) { |
24 | | - $wgOut->addHTML( wfMsg( 'ow_exporttsv_not_allowed' ) ); |
| 29 | + require_once( 'WikiDataAPI.php' ); |
| 30 | + require_once( 'Transaction.php' ); |
| 31 | + // get the collection to export. Cut off the 'cid' part that we added |
| 32 | + // to make the keys strings rather than numbers in the array sent to the form. |
| 33 | + $collectionId = substr( $wgRequest->getText( 'collection' ), 3 ); |
| 34 | + // get the languages requested, turn into an array, trim for spaces. |
| 35 | + $isoCodes = explode( ',', $wgRequest->getText( 'languages' ) ); |
| 36 | + for ( $i = 0; $i < count( $isoCodes ); $i++ ) { |
| 37 | + $isoCodes[$i] = trim( $isoCodes[$i] ); |
| 38 | + if ( !getLanguageIdForIso639_3( $isoCodes[$i] ) ) { |
| 39 | + $wgOut->setPageTitle( wfMsg( 'ow_exporttsv_export_failed' ) ); |
| 40 | + $wgOut->addHTML( wfMsg( 'ow_impexptsv_unknown_lang', $isoCodes[$i] ) ); |
25 | 41 | return false; |
26 | 42 | } |
27 | | - |
28 | | - $dbr = wfGetDB( DB_SLAVE ); |
29 | | - $dc = wdGetDataSetcontext(); |
30 | | - |
31 | | - if ( $wgRequest->getText( 'collection' ) && $wgRequest->getText( 'languages' ) ) { |
32 | | - // render the tsv file |
| 43 | + } |
| 44 | + |
| 45 | + $wgOut->disable(); |
| 46 | + |
| 47 | + $languages = $this->getLanguages( $isoCodes ); |
| 48 | + $isoLookup = $this->createIsoLookup( $languages ); |
| 49 | + $downloadFileName = $this->createFileName( $isoCodes ); |
| 50 | + |
| 51 | + // Force the browser into a download |
| 52 | + header( 'Content-Type: text/tab-separated-values;charset=utf-8' ); |
| 53 | + header( 'Content-Disposition: attachment; filename="' . $downloadFileName . '"' ); // attachment |
33 | 54 | |
34 | | - require_once( 'WikiDataAPI.php' ); |
35 | | - require_once( 'Transaction.php' ); |
36 | | - // get the collection to export. Cut off the 'cid' part that we added |
37 | | - // to make the keys strings rather than numbers in the array sent to the form. |
38 | | - $collectionId = substr( $wgRequest->getText( 'collection' ), 3 ); |
39 | | - // get the languages requested, turn into an array, trim for spaces. |
40 | | - $isoCodes = explode( ',', $wgRequest->getText( 'languages' ) ); |
41 | | - for ( $i = 0; $i < count( $isoCodes ); $i++ ) { |
42 | | - $isoCodes[$i] = trim( $isoCodes[$i] ); |
43 | | - if ( !getLanguageIdForIso639_3( $isoCodes[$i] ) ) { |
44 | | - $wgOut->setPageTitle( wfMsg( 'ow_exporttsv_export_failed' ) ); |
45 | | - $wgOut->addHTML( wfMsg( 'ow_impexptsv_unknown_lang', $isoCodes[$i] ) ); |
46 | | - return false; |
47 | | - } |
48 | | - } |
49 | | - |
50 | | - $wgOut->disable(); |
51 | | - |
52 | | - $languages = $this->getLanguages( $isoCodes ); |
53 | | - $isoLookup = $this->createIsoLookup( $languages ); |
54 | | - $downloadFileName = $this->createFileName( $isoCodes ); |
55 | | - |
56 | | - // Force the browser into a download |
57 | | - header( 'Content-Type: text/tab-separated-values;charset=utf-8' ); |
58 | | - header( 'Content-Disposition: attachment; filename="' . $downloadFileName . '"' ); // attachment |
| 55 | + // separator character used. |
| 56 | + $sc = "\t"; |
| 57 | + |
| 58 | + echo( pack( 'CCC', 0xef, 0xbb, 0xbf ) ); |
| 59 | + // start the first row: column names |
| 60 | + echo( 'defined meaning id' . $sc . 'defining expression' ); |
| 61 | + foreach ( $isoCodes as $isoCode ) { |
| 62 | + echo( $sc . 'definition_' . $isoCode . $sc . 'translations_' . $isoCode ); |
| 63 | + } |
| 64 | + echo( "\r\n" ); |
| 65 | + |
| 66 | + // get all the defined meanings in the collection |
| 67 | + $query = "SELECT dm.defined_meaning_id, exp.spelling "; |
| 68 | + $query .= "FROM {$dc}_collection_contents col, {$dc}_defined_meaning dm, {$dc}_expression exp "; |
| 69 | + $query .= "WHERE col.collection_id=" . $collectionId . " "; |
| 70 | + $query .= "AND col.member_mid=dm.defined_meaning_id "; |
| 71 | + $query .= "AND dm.expression_id = exp.expression_id "; |
| 72 | + $query .= "AND " . getLatestTransactionRestriction( "col" ); |
| 73 | + $query .= "AND " . getLatestTransactionRestriction( "dm" ); |
| 74 | + $query .= "AND " . getLatestTransactionRestriction( "exp" ); |
| 75 | + $query .= "ORDER BY exp.spelling"; |
| 76 | + |
| 77 | + // wfDebug($query."\n"); |
59 | 78 | |
60 | | - // separator character used. |
61 | | - $sc = "\t"; |
62 | | - |
63 | | - echo( pack( 'CCC', 0xef, 0xbb, 0xbf ) ); |
64 | | - // start the first row: column names |
65 | | - echo( 'defined meaning id' . $sc . 'defining expression' ); |
66 | | - foreach ( $isoCodes as $isoCode ) { |
67 | | - echo( $sc . 'definition_' . $isoCode . $sc . 'translations_' . $isoCode ); |
68 | | - } |
69 | | - echo( "\r\n" ); |
70 | | - |
71 | | - // get all the defined meanings in the collection |
72 | | - $query = "SELECT dm.defined_meaning_id, exp.spelling "; |
73 | | - $query .= "FROM {$dc}_collection_contents col, {$dc}_defined_meaning dm, {$dc}_expression exp "; |
74 | | - $query .= "WHERE col.collection_id=" . $collectionId . " "; |
75 | | - $query .= "AND col.member_mid=dm.defined_meaning_id "; |
76 | | - $query .= "AND dm.expression_id = exp.expression_id "; |
77 | | - $query .= "AND " . getLatestTransactionRestriction( "col" ); |
78 | | - $query .= "AND " . getLatestTransactionRestriction( "dm" ); |
79 | | - $query .= "AND " . getLatestTransactionRestriction( "exp" ); |
80 | | - $query .= "ORDER BY exp.spelling"; |
81 | | - |
82 | | - // wfDebug($query."\n"); |
| 79 | + $queryResult = $dbr->query( $query ); |
| 80 | + while ( $row = $dbr->fetchRow( $queryResult ) ) { |
| 81 | + $dm_id = $row['defined_meaning_id']; |
| 82 | + // echo the defined meaning id and the defining expression |
| 83 | + echo( $dm_id ); |
| 84 | + echo( "\t" . $row['spelling'] ); |
| 85 | + |
| 86 | + // First we'll fill an associative array with the definitions and |
| 87 | + // translations. Then we'll use the isoCodes array to put them in the |
| 88 | + // proper order. |
83 | 89 | |
84 | | - $queryResult = $dbr->query( $query ); |
85 | | - while ( $row = $dbr->fetchRow( $queryResult ) ) { |
86 | | - $dm_id = $row['defined_meaning_id']; |
87 | | - // echo the defined meaning id and the defining expression |
88 | | - echo( $dm_id ); |
89 | | - echo( "\t" . $row['spelling'] ); |
90 | | - |
91 | | - // First we'll fill an associative array with the definitions and |
92 | | - // translations. Then we'll use the isoCodes array to put them in the |
93 | | - // proper order. |
| 90 | + // the associative array holding the definitions and translations |
| 91 | + $data = array(); |
| 92 | + |
| 93 | + // **************************** |
| 94 | + // query to get the definitions |
| 95 | + // **************************** |
| 96 | + $qry = 'SELECT txt.text_text, trans.language_id '; |
| 97 | + $qry .= "FROM {$dc}_text txt, {$dc}_translated_content trans, {$dc}_defined_meaning dm "; |
| 98 | + $qry .= 'WHERE txt.text_id = trans.text_id '; |
| 99 | + $qry .= 'AND trans.translated_content_id = dm.meaning_text_tcid '; |
| 100 | + $qry .= "AND dm.defined_meaning_id = $dm_id "; |
| 101 | + $qry .= 'AND trans.language_id IN ('; |
| 102 | + for ( $i = 0; $i < count( $languages ); $i++ ) { |
| 103 | + $language = $languages[$i]; |
| 104 | + if ( $i > 0 ) |
| 105 | + $qry .= ","; |
| 106 | + $qry .= $language['language_id']; |
| 107 | + } |
| 108 | + $qry .= ') AND ' . getLatestTransactionRestriction( 'trans' ); |
| 109 | + $qry .= 'AND ' . getLatestTransactionRestriction( 'dm' ); |
| 110 | + |
| 111 | + // wfDebug($qry."\n"); // uncomment this if you accept having 1700+ queries in the log |
94 | 112 | |
95 | | - // the associative array holding the definitions and translations |
96 | | - $data = array(); |
97 | | - |
98 | | - // **************************** |
99 | | - // query to get the definitions |
100 | | - // **************************** |
101 | | - $qry = 'SELECT txt.text_text, trans.language_id '; |
102 | | - $qry .= "FROM {$dc}_text txt, {$dc}_translated_content trans, {$dc}_defined_meaning dm "; |
103 | | - $qry .= 'WHERE txt.text_id = trans.text_id '; |
104 | | - $qry .= 'AND trans.translated_content_id = dm.meaning_text_tcid '; |
105 | | - $qry .= "AND dm.defined_meaning_id = $dm_id "; |
106 | | - $qry .= 'AND trans.language_id IN ('; |
107 | | - for ( $i = 0; $i < count( $languages ); $i++ ) { |
108 | | - $language = $languages[$i]; |
109 | | - if ( $i > 0 ) |
110 | | - $qry .= ","; |
111 | | - $qry .= $language['language_id']; |
112 | | - } |
113 | | - $qry .= ') AND ' . getLatestTransactionRestriction( 'trans' ); |
114 | | - $qry .= 'AND ' . getLatestTransactionRestriction( 'dm' ); |
115 | | - |
116 | | - // wfDebug($qry."\n"); // uncomment this if you accept having 1700+ queries in the log |
| 113 | + $definitions = $dbr->query( $qry ); |
| 114 | + while ( $row = $dbr->fetchRow( $definitions ) ) { |
| 115 | + // $key becomes something like def_eng |
| 116 | + $key = 'def_' . $isoLookup['id' . $row['language_id']]; |
| 117 | + $data[$key] = $row['text_text']; |
| 118 | + } |
| 119 | + $dbr->freeResult( $definitions ); |
| 120 | + |
| 121 | + // ***************************** |
| 122 | + // query to get the translations |
| 123 | + // ***************************** |
| 124 | + $qry = "SELECT exp.spelling, exp.language_id "; |
| 125 | + $qry .= "FROM {$dc}_expression exp "; |
| 126 | + $qry .= "INNER JOIN {$dc}_syntrans trans ON exp.expression_id=trans.expression_id "; |
| 127 | + $qry .= "WHERE trans.defined_meaning_id=$dm_id "; |
| 128 | + $qry .= "AND " . getLatestTransactionRestriction( "exp" ); |
| 129 | + $qry .= "AND " . getLatestTransactionRestriction( "trans" ); |
| 130 | + |
| 131 | + // wfDebug($qry."\n"); // uncomment this if you accept having 1700+ queries in the log |
117 | 132 | |
118 | | - $definitions = $dbr->query( $qry ); |
119 | | - while ( $row = $dbr->fetchRow( $definitions ) ) { |
120 | | - // $key becomes something like def_eng |
121 | | - $key = 'def_' . $isoLookup['id' . $row['language_id']]; |
122 | | - $data[$key] = $row['text_text']; |
123 | | - } |
124 | | - $dbr->freeResult( $definitions ); |
125 | | - |
126 | | - // ***************************** |
127 | | - // query to get the translations |
128 | | - // ***************************** |
129 | | - $qry = "SELECT exp.spelling, exp.language_id "; |
130 | | - $qry .= "FROM {$dc}_expression exp "; |
131 | | - $qry .= "INNER JOIN {$dc}_syntrans trans ON exp.expression_id=trans.expression_id "; |
132 | | - $qry .= "WHERE trans.defined_meaning_id=$dm_id "; |
133 | | - $qry .= "AND " . getLatestTransactionRestriction( "exp" ); |
134 | | - $qry .= "AND " . getLatestTransactionRestriction( "trans" ); |
135 | | - |
136 | | - // wfDebug($qry."\n"); // uncomment this if you accept having 1700+ queries in the log |
137 | | - |
138 | | - $translations = $dbr->query( $qry ); |
139 | | - while ( $row = $dbr->fetchRow( $translations ) ) { |
140 | | - // qry gets all languages, we filter them here. Saves an order |
141 | | - // of magnitude execution time. |
142 | | - if ( isset( $isoLookup['id' . $row['language_id']] ) ) { |
143 | | - // $key becomes something like trans_eng |
144 | | - $key = 'trans_' . $isoLookup['id' . $row['language_id']]; |
145 | | - if ( !isset( $data[$key] ) ) |
146 | | - $data[$key] = $row['spelling']; |
147 | | - else |
148 | | - $data[$key] = $data[$key] . '|' . $row['spelling']; |
149 | | - } |
150 | | - } |
151 | | - $dbr->freeResult( $translations ); |
152 | | - |
153 | | - |
154 | | - |
155 | | - // now that we have everything, output the row. |
156 | | - foreach ( $isoCodes as $isoCode ) { |
157 | | - // if statements save a bunch of notices in the log about |
158 | | - // undefined indices. |
159 | | - echo( "\t" ); |
160 | | - if ( isset( $data['def_' . $isoCode] ) ) |
161 | | - echo( $this->escapeDelimitedValue( $data['def_' . $isoCode] ) ); |
162 | | - echo( "\t" ); |
163 | | - if ( isset( $data['trans_' . $isoCode] ) ) |
164 | | - echo( $data['trans_' . $isoCode] ); |
165 | | - } |
166 | | - echo( "\r\n" ); |
| 133 | + $translations = $dbr->query( $qry ); |
| 134 | + while ( $row = $dbr->fetchRow( $translations ) ) { |
| 135 | + // qry gets all languages, we filter them here. Saves an order |
| 136 | + // of magnitude execution time. |
| 137 | + if ( isset( $isoLookup['id' . $row['language_id']] ) ) { |
| 138 | + // $key becomes something like trans_eng |
| 139 | + $key = 'trans_' . $isoLookup['id' . $row['language_id']]; |
| 140 | + if ( !isset( $data[$key] ) ) |
| 141 | + $data[$key] = $row['spelling']; |
| 142 | + else |
| 143 | + $data[$key] = $data[$key] . '|' . $row['spelling']; |
167 | 144 | } |
168 | | - |
169 | | - |
170 | 145 | } |
171 | | - else { |
172 | | - |
173 | | - // Get the collections |
174 | | - $colQuery = "SELECT col.collection_id, exp.spelling " . |
175 | | - "FROM {$dc}_collection col INNER JOIN {$dc}_defined_meaning dm ON col.collection_mid=dm.defined_meaning_id " . |
176 | | - "INNER JOIN {$dc}_expression exp ON dm.expression_id=exp.expression_id " . |
177 | | - "WHERE " . getLatestTransactionRestriction( 'col' ); |
178 | | - |
179 | | - $collections = array(); |
180 | | - $colResults = $dbr->query( $colQuery ); |
181 | | - while ( $row = $dbr->fetchRow( $colResults ) ) { |
182 | | - $collections['cid' . $row['collection_id']] = $row['spelling']; |
183 | | - } |
| 146 | + $dbr->freeResult( $translations ); |
| 147 | + |
184 | 148 | |
185 | | - // render the page |
186 | | - $wgOut->setPageTitle( wfMsg( 'ow_exporttsv_title' ) ); |
187 | | - $wgOut->addHTML( wfMsg( 'ow_exporttsv_header' ) ); |
188 | | - |
189 | | - $wgOut->addHTML( getOptionPanel( |
190 | | - array( |
191 | | - wfMsg( 'ow_Collection_colon' ) => getSelect( 'collection', $collections, 'cid376322' ), |
192 | | - wfMsg( 'ow_exporttsv_languages' ) => getTextBox( 'languages', 'ita, eng, deu, fra, cat' ), |
193 | | - ), |
194 | | - '', array( 'create' => wfMsg( 'ow_create' ) ) |
195 | | - ) ); |
| 149 | + |
| 150 | + // now that we have everything, output the row. |
| 151 | + foreach ( $isoCodes as $isoCode ) { |
| 152 | + // if statements save a bunch of notices in the log about |
| 153 | + // undefined indices. |
| 154 | + echo( "\t" ); |
| 155 | + if ( isset( $data['def_' . $isoCode] ) ) |
| 156 | + echo( $this->escapeDelimitedValue( $data['def_' . $isoCode] ) ); |
| 157 | + echo( "\t" ); |
| 158 | + if ( isset( $data['trans_' . $isoCode] ) ) |
| 159 | + echo( $data['trans_' . $isoCode] ); |
196 | 160 | } |
197 | | - |
| 161 | + echo( "\r\n" ); |
198 | 162 | } |
199 | 163 | |
200 | 164 | |
201 | | - /* HELPER METHODS START HERE */ |
| 165 | + } |
| 166 | + else { |
202 | 167 | |
203 | | - function escapeDelimitedValue( $value ) { |
204 | | - $newValue = str_replace( '"', '""', $value ); |
205 | | - // Unfortunately, excell doesn't handle line brakes correctly, even if they are in quotes. |
206 | | - // we'll just remove them. |
207 | | - $newValue = str_replace( "\r\n", ' ', $value ); |
208 | | - $newValue = str_replace( "\n", ' ', $value ); |
209 | | - // quoting the string is always allowed, so lets check for all possible separator characters |
210 | | - if ( $value != $newValue || strpos( $value, ',' ) || strpos( $value, ';' ) || strpos( $value, '\t' ) ) { |
211 | | - $newValue = '"' . $newValue . '"'; |
212 | | - } |
213 | | - return $newValue; |
214 | | - } |
| 168 | + // Get the collections |
| 169 | + $colQuery = "SELECT col.collection_id, exp.spelling " . |
| 170 | + "FROM {$dc}_collection col INNER JOIN {$dc}_defined_meaning dm ON col.collection_mid=dm.defined_meaning_id " . |
| 171 | + "INNER JOIN {$dc}_expression exp ON dm.expression_id=exp.expression_id " . |
| 172 | + "WHERE " . getLatestTransactionRestriction( 'col' ); |
215 | 173 | |
216 | | - /** |
217 | | - * Get id and iso639_3 language names for the given comma-separated |
218 | | - * list of iso639_3 language names. |
219 | | - */ |
220 | | - function getLanguages( $isoCodes ) { |
221 | | - // create query to look up the language codes. |
222 | | - $langQuery = "SELECT language_id, iso639_3 FROM language WHERE "; |
223 | | - foreach ( $isoCodes as $isoCode ) { |
224 | | - $isoCode = trim( $isoCode ); |
225 | | - // if query does not end in WHERE , prepend OR. |
226 | | - if ( strpos( $langQuery, "WHERE " ) + 6 < strlen( $langQuery ) ) { |
227 | | - $langQuery .= " OR "; |
228 | | - } |
229 | | - $langQuery .= "iso639_3='$isoCode'"; |
230 | | - } |
231 | | - // Order by id so we can order the definitions and translations the same way. |
232 | | - $langQuery .= " ORDER BY language_id"; |
233 | | - |
234 | | - // wfDebug($langQuery."\n"); |
235 | | - |
236 | | - $languages = array(); |
237 | | - $dbr = wfGetDB( DB_SLAVE ); |
238 | | - $langResults = $dbr->query( $langQuery ); |
239 | | - while ( $row = $dbr->fetchRow( $langResults ) ) { |
240 | | - $languages[] = $row; |
241 | | - } |
242 | | - |
243 | | - return $languages; |
| 174 | + $collections = array(); |
| 175 | + $colResults = $dbr->query( $colQuery ); |
| 176 | + while ( $row = $dbr->fetchRow( $colResults ) ) { |
| 177 | + $collections['cid' . $row['collection_id']] = $row['spelling']; |
244 | 178 | } |
| 179 | + |
| 180 | + // render the page |
| 181 | + $wgOut->setPageTitle( wfMsg( 'ow_exporttsv_title' ) ); |
| 182 | + $wgOut->addHTML( wfMsg( 'ow_exporttsv_header' ) ); |
245 | 183 | |
246 | | - function createIsoLookup( $languages ) { |
247 | | - $lookup = array(); |
248 | | - foreach ( $languages as $language ) { |
249 | | - $lookup['id' . $language['language_id']] = $language['iso639_3']; |
250 | | - } |
251 | | - return $lookup; |
252 | | - } |
253 | | - |
254 | | - /** |
255 | | - * Create the file name based on the languages requested. |
256 | | - * Change file name prefix and suffix here. |
257 | | - */ |
258 | | - function createFileName( $isoCodes ) { |
259 | | - $fileName = "destit_"; |
260 | | - for ( $i = 0; $i < count( $isoCodes ); $i++ ) { |
261 | | - $isoCode = $isoCodes[$i]; |
262 | | - if ( $i > 0 ) |
263 | | - $fileName .= '-'; |
264 | | - $fileName .= $isoCode; |
265 | | - } |
266 | | - $fileName .= ".txt"; |
267 | | - return $fileName; |
268 | | - } |
| 184 | + $wgOut->addHTML( getOptionPanel( |
| 185 | + array( |
| 186 | + wfMsg( 'ow_Collection_colon' ) => getSelect( 'collection', $collections, 'cid376322' ), |
| 187 | + wfMsg( 'ow_exporttsv_languages' ) => getTextBox( 'languages', 'ita, eng, deu, fra, cat' ), |
| 188 | + ), |
| 189 | + '', array( 'create' => wfMsg( 'ow_create' ) ) |
| 190 | + ) ); |
269 | 191 | } |
270 | 192 | |
271 | | - SpecialPage::addPage( new SpecialExportTSV ); |
272 | 193 | } |
| 194 | + |
| 195 | + |
| 196 | + /* HELPER METHODS START HERE */ |
| 197 | + |
| 198 | + function escapeDelimitedValue( $value ) { |
| 199 | + $newValue = str_replace( '"', '""', $value ); |
| 200 | + // Unfortunately, excell doesn't handle line brakes correctly, even if they are in quotes. |
| 201 | + // we'll just remove them. |
| 202 | + $newValue = str_replace( "\r\n", ' ', $value ); |
| 203 | + $newValue = str_replace( "\n", ' ', $value ); |
| 204 | + // quoting the string is always allowed, so lets check for all possible separator characters |
| 205 | + if ( $value != $newValue || strpos( $value, ',' ) || strpos( $value, ';' ) || strpos( $value, '\t' ) ) { |
| 206 | + $newValue = '"' . $newValue . '"'; |
| 207 | + } |
| 208 | + return $newValue; |
| 209 | + } |
| 210 | + |
| 211 | + /** |
| 212 | + * Get id and iso639_3 language names for the given comma-separated |
| 213 | + * list of iso639_3 language names. |
| 214 | + */ |
| 215 | + function getLanguages( $isoCodes ) { |
| 216 | + // create query to look up the language codes. |
| 217 | + $langQuery = "SELECT language_id, iso639_3 FROM language WHERE "; |
| 218 | + foreach ( $isoCodes as $isoCode ) { |
| 219 | + $isoCode = trim( $isoCode ); |
| 220 | + // if query does not end in WHERE , prepend OR. |
| 221 | + if ( strpos( $langQuery, "WHERE " ) + 6 < strlen( $langQuery ) ) { |
| 222 | + $langQuery .= " OR "; |
| 223 | + } |
| 224 | + $langQuery .= "iso639_3='$isoCode'"; |
| 225 | + } |
| 226 | + // Order by id so we can order the definitions and translations the same way. |
| 227 | + $langQuery .= " ORDER BY language_id"; |
| 228 | + |
| 229 | + // wfDebug($langQuery."\n"); |
273 | 230 | |
| 231 | + $languages = array(); |
| 232 | + $dbr = wfGetDB( DB_SLAVE ); |
| 233 | + $langResults = $dbr->query( $langQuery ); |
| 234 | + while ( $row = $dbr->fetchRow( $langResults ) ) { |
| 235 | + $languages[] = $row; |
| 236 | + } |
| 237 | + |
| 238 | + return $languages; |
| 239 | + } |
| 240 | + |
| 241 | + function createIsoLookup( $languages ) { |
| 242 | + $lookup = array(); |
| 243 | + foreach ( $languages as $language ) { |
| 244 | + $lookup['id' . $language['language_id']] = $language['iso639_3']; |
| 245 | + } |
| 246 | + return $lookup; |
| 247 | + } |
| 248 | + |
| 249 | + /** |
| 250 | + * Create the file name based on the languages requested. |
| 251 | + * Change file name prefix and suffix here. |
| 252 | + */ |
| 253 | + function createFileName( $isoCodes ) { |
| 254 | + $fileName = "destit_"; |
| 255 | + for ( $i = 0; $i < count( $isoCodes ); $i++ ) { |
| 256 | + $isoCode = $isoCodes[$i]; |
| 257 | + if ( $i > 0 ) |
| 258 | + $fileName .= '-'; |
| 259 | + $fileName .= $isoCode; |
| 260 | + } |
| 261 | + $fileName .= ".txt"; |
| 262 | + return $fileName; |
| 263 | + } |
| 264 | +} |
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialSelect.php |
— | — | @@ -2,88 +2,53 @@ |
3 | 3 | |
4 | 4 | if ( !defined( 'MEDIAWIKI' ) ) die(); |
5 | 5 | |
6 | | -$wgExtensionFunctions[] = 'wfSpecialSelect'; |
7 | 6 | require_once( "Wikidata.php" ); |
8 | 7 | require_once( "WikiDataGlobals.php" ); |
9 | 8 | |
10 | | - |
11 | | -function wfSpecialSelect() { |
12 | | - class SpecialSelect extends SpecialPage { |
13 | | - function SpecialSelect() { |
14 | | - parent::__construct( 'Select', 'UnlistedSpecialPage' ); |
15 | | - } |
16 | | - |
17 | | - function execute( $par ) { |
18 | | - require_once( 'languages.php' ); |
19 | | - require_once( 'Transaction.php' ); |
20 | | - global |
21 | | - $wgOut, $IP; |
22 | | - |
23 | | - $wgOut->disable(); |
24 | | - |
25 | | - echo getSelectOptions(); |
26 | | - } |
| 9 | +class SpecialSelect extends SpecialPage { |
| 10 | + function SpecialSelect() { |
| 11 | + parent::__construct( 'Select', 'UnlistedSpecialPage' ); |
27 | 12 | } |
28 | 13 | |
29 | | - SpecialPage::addPage( new SpecialSelect() ); |
30 | | -} |
| 14 | + function execute( $par ) { |
| 15 | + require_once( 'languages.php' ); |
| 16 | + require_once( 'Transaction.php' ); |
| 17 | + global $wgOut, $wgLang, $wgRequest, $wgOptionAttribute; |
31 | 18 | |
32 | | -function getSelectOptions() { |
33 | | - global $wgLang, $wgOptionAttribute; |
| 19 | + $wgOut->disable(); |
34 | 20 | |
35 | | - $dc = wdGetDataSetContext(); |
36 | | - $optionAttribute = $_GET[$wgOptionAttribute]; |
37 | | - $attributeObject = $_GET['attribute-object']; |
38 | | - $lang_code = $wgLang->getCode(); |
| 21 | + $dc = wdGetDataSetContext(); |
| 22 | + $optionAttribute = $wgRequest->getVal( $wgOptionAttribute ); |
| 23 | + $attributeObject = $wgRequest->getVal( 'attribute-object' ); |
| 24 | + $lang_code = $wgLang->getCode(); |
39 | 25 | |
40 | | - $dbr = wfGetDB( DB_SLAVE ); |
41 | | - $sql = 'SELECT language_id' . |
42 | | - " FROM {$dc}_syntrans" . |
43 | | - " JOIN {$dc}_expression ON {$dc}_expression.expression_id = {$dc}_syntrans.expression_id" . |
44 | | - " WHERE {$dc}_syntrans.syntrans_sid = " . $attributeObject . |
45 | | - ' AND ' . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
46 | | - ' AND ' . getLatestTransactionRestriction( "{$dc}_expression" ); |
47 | | - $lang_res = $dbr->query( $sql ); |
48 | | - $objectLanguage = $dbr->fetchObject( $lang_res )->language_id; |
49 | | - // language is not always defined, for example for a DM Option Attribute |
50 | | - if ( ! $objectLanguage ) $objectLanguage = 0 ; |
| 26 | + $dbr = wfGetDB( DB_SLAVE ); |
| 27 | + $sql = 'SELECT language_id' . |
| 28 | + " FROM {$dc}_syntrans" . |
| 29 | + " JOIN {$dc}_expression ON {$dc}_expression.expression_id = {$dc}_syntrans.expression_id" . |
| 30 | + " WHERE {$dc}_syntrans.syntrans_sid = " . $attributeObject . |
| 31 | + ' AND ' . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
| 32 | + ' AND ' . getLatestTransactionRestriction( "{$dc}_expression" ); |
| 33 | + $lang_res = $dbr->query( $sql ); |
| 34 | + $objectLanguage = $dbr->fetchObject( $lang_res )->language_id; |
| 35 | + // language is not always defined, for example for a DM Option Attribute |
| 36 | + if ( ! $objectLanguage ) $objectLanguage = 0 ; |
51 | 37 | |
52 | | - $sql = "SELECT {$dc}_option_attribute_options.option_id,{$dc}_option_attribute_options.option_mid" . |
53 | | - " FROM {$dc}_option_attribute_options" . |
54 | | - " JOIN {$dc}_class_attributes ON {$dc}_class_attributes.object_id = {$dc}_option_attribute_options.attribute_id" . |
55 | | - " WHERE {$dc}_class_attributes.attribute_mid = " . $optionAttribute . |
56 | | - " AND ({$dc}_option_attribute_options.language_id = " . $objectLanguage . |
57 | | - " OR {$dc}_option_attribute_options.language_id = 0)" . |
58 | | - ' AND ' . getLatestTransactionRestriction( "{$dc}_option_attribute_options" ) . |
59 | | - ' AND ' . getLatestTransactionRestriction( "{$dc}_class_attributes" ); |
60 | | - $options_res = $dbr->query( $sql ); |
| 38 | + $sql = "SELECT {$dc}_option_attribute_options.option_id,{$dc}_option_attribute_options.option_mid" . |
| 39 | + " FROM {$dc}_option_attribute_options" . |
| 40 | + " JOIN {$dc}_class_attributes ON {$dc}_class_attributes.object_id = {$dc}_option_attribute_options.attribute_id" . |
| 41 | + " WHERE {$dc}_class_attributes.attribute_mid = " . $optionAttribute . |
| 42 | + " AND ({$dc}_option_attribute_options.language_id = " . $objectLanguage . |
| 43 | + " OR {$dc}_option_attribute_options.language_id = 0)" . |
| 44 | + ' AND ' . getLatestTransactionRestriction( "{$dc}_option_attribute_options" ) . |
| 45 | + ' AND ' . getLatestTransactionRestriction( "{$dc}_class_attributes" ); |
| 46 | + $options_res = $dbr->query( $sql ); |
61 | 47 | |
62 | | - $optionsString = ''; |
63 | | - $optionsArray = array() ; |
64 | | - while ( $options_row = $dbr->fetchObject( $options_res ) ) { |
65 | | - /* Use a simpler query if the user's language is English. */ |
66 | | - if ( $lang_code == 'en' || !( $lang_id = getLanguageIdForCode( $lang_code ) ) ) { |
67 | | - $sql = "SELECT {$dc}_expression.spelling" . |
68 | | - " FROM {$dc}_syntrans" . |
69 | | - " JOIN {$dc}_expression ON {$dc}_expression.expression_id = {$dc}_syntrans.expression_id" . |
70 | | - " WHERE {$dc}_syntrans.defined_meaning_id = " . $options_row->option_mid . |
71 | | - " AND {$dc}_expression.language_id = " . getLanguageIdForCode( 'en' ) . |
72 | | - ' AND ' . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
73 | | - ' AND ' . getLatestTransactionRestriction( "{$dc}_expression" ); |
74 | | - } |
75 | | - /* Fall back on English in cases where an option name is not present in the |
76 | | - user's preferred language. */ |
77 | | - else { |
78 | | - /* XXX: This setup is really hacked together. It NEEDS to be improved. */ |
79 | | - $sql = "SELECT {$dc}_expression.spelling" . |
80 | | - " FROM {$dc}_syntrans" . |
81 | | - " JOIN {$dc}_expression ON {$dc}_expression.expression_id = {$dc}_syntrans.expression_id" . |
82 | | - " WHERE {$dc}_syntrans.defined_meaning_id = " . $options_row->option_mid . |
83 | | - " AND {$dc}_expression.language_id = " . $lang_id . |
84 | | - ' AND ' . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
85 | | - ' AND ' . getLatestTransactionRestriction( "{$dc}_expression" ); |
86 | | - $res = $dbr->query( $sql ); |
87 | | - if ( !$dbr->fetchObject( $res )->spelling ) |
| 48 | + $optionsString = ''; |
| 49 | + $optionsArray = array() ; |
| 50 | + while ( $options_row = $dbr->fetchObject( $options_res ) ) { |
| 51 | + /* Use a simpler query if the user's language is English. */ |
| 52 | + if ( $lang_code == 'en' || !( $lang_id = getLanguageIdForCode( $lang_code ) ) ) { |
88 | 53 | $sql = "SELECT {$dc}_expression.spelling" . |
89 | 54 | " FROM {$dc}_syntrans" . |
90 | 55 | " JOIN {$dc}_expression ON {$dc}_expression.expression_id = {$dc}_syntrans.expression_id" . |
— | — | @@ -91,21 +56,41 @@ |
92 | 57 | " AND {$dc}_expression.language_id = " . getLanguageIdForCode( 'en' ) . |
93 | 58 | ' AND ' . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
94 | 59 | ' AND ' . getLatestTransactionRestriction( "{$dc}_expression" ); |
95 | | - } |
| 60 | + } |
| 61 | + /* Fall back on English in cases where an option name is not present in the |
| 62 | + user's preferred language. */ |
| 63 | + else { |
| 64 | + /* XXX: This setup is really hacked together. It NEEDS to be improved. */ |
| 65 | + $sql = "SELECT {$dc}_expression.spelling" . |
| 66 | + " FROM {$dc}_syntrans" . |
| 67 | + " JOIN {$dc}_expression ON {$dc}_expression.expression_id = {$dc}_syntrans.expression_id" . |
| 68 | + " WHERE {$dc}_syntrans.defined_meaning_id = " . $options_row->option_mid . |
| 69 | + " AND {$dc}_expression.language_id = " . $lang_id . |
| 70 | + ' AND ' . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
| 71 | + ' AND ' . getLatestTransactionRestriction( "{$dc}_expression" ); |
| 72 | + $res = $dbr->query( $sql ); |
| 73 | + if ( !$dbr->fetchObject( $res )->spelling ) |
| 74 | + $sql = "SELECT {$dc}_expression.spelling" . |
| 75 | + " FROM {$dc}_syntrans" . |
| 76 | + " JOIN {$dc}_expression ON {$dc}_expression.expression_id = {$dc}_syntrans.expression_id" . |
| 77 | + " WHERE {$dc}_syntrans.defined_meaning_id = " . $options_row->option_mid . |
| 78 | + " AND {$dc}_expression.language_id = " . getLanguageIdForCode( 'en' ) . |
| 79 | + ' AND ' . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
| 80 | + ' AND ' . getLatestTransactionRestriction( "{$dc}_expression" ); |
| 81 | + } |
96 | 82 | |
97 | | - $spelling_res = $dbr->query( $sql ); |
98 | | - $spelling_row = $dbr->fetchObject( $spelling_res ); |
| 83 | + $spelling_res = $dbr->query( $sql ); |
| 84 | + $spelling_row = $dbr->fetchObject( $spelling_res ); |
99 | 85 | |
100 | | - $optionsArray[$options_row->option_id] = $spelling_row->spelling ; |
101 | | - } |
| 86 | + $optionsArray[$options_row->option_id] = $spelling_row->spelling ; |
| 87 | + } |
102 | 88 | |
103 | | - asort( $optionsArray ) ; |
104 | | - foreach ($optionsArray as $option_id => $spelling ) { |
105 | | - if ( $optionsString != '' ) $optionsString .= "\n"; |
106 | | - $optionsString .= $option_id . ';' . $spelling ; |
107 | | - } |
| 89 | + asort( $optionsArray ) ; |
| 90 | + foreach ($optionsArray as $option_id => $spelling ) { |
| 91 | + if ( $optionsString != '' ) $optionsString .= "\n"; |
| 92 | + $optionsString .= $option_id . ';' . $spelling ; |
| 93 | + } |
108 | 94 | |
109 | | - return $optionsString; |
| 95 | + echo $optionsString; |
| 96 | + } |
110 | 97 | } |
111 | | - |
112 | | - |
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialSuggest.php |
— | — | @@ -3,300 +3,281 @@ |
4 | 4 | if ( !defined( 'MEDIAWIKI' ) ) die(); |
5 | 5 | |
6 | 6 | |
7 | | -$wgExtensionFunctions[] = 'wfSpecialSuggest'; |
8 | | -function wfSpecialSuggest() { |
9 | | - class SpecialSuggest extends SpecialPage { |
10 | | - function SpecialSuggest() { |
11 | | - parent::__construct( 'Suggest', 'UnlistedSpecialPage' ); |
12 | | - |
13 | | - } |
| 7 | +class SpecialSuggest extends SpecialPage { |
| 8 | + function __construct() { |
| 9 | + parent::__construct( 'Suggest', 'UnlistedSpecialPage' ); |
| 10 | + } |
14 | 11 | |
15 | | - function execute( $par ) { |
16 | | - global |
17 | | - $wgOut, $IP; |
| 12 | + function execute( $par ) { |
| 13 | + global $wgOut, $wgLang, $wgRequest, $IP, |
| 14 | + $wgDefinedMeaning, $wgDefinedMeaningAttributes, |
| 15 | + $wgOptionAttribute, $wgLinkAttribute; |
18 | 16 | |
19 | | - $wgOut->disable(); |
20 | | - require_once( "$IP/includes/Setup.php" ); |
21 | | - require_once( "Attribute.php" ); |
22 | | - require_once( "WikiDataBootstrappedMeanings.php" ); |
23 | | - require_once( "RecordSet.php" ); |
24 | | - require_once( "Editor.php" ); |
25 | | - require_once( "HTMLtable.php" ); |
26 | | - # require_once("WikiDataAPI.php"); |
27 | | - require_once( "Transaction.php" ); |
28 | | - require_once( "OmegaWikiEditors.php" ); |
29 | | - require_once( "Utilities.php" ); |
30 | | - require_once( "Wikidata.php" ); |
31 | | - require_once( "WikiDataTables.php" ); |
32 | | - require_once( "WikiDataGlobals.php" ); |
33 | | - echo getSuggestions(); |
34 | | - } |
35 | | - } |
| 17 | + $wgOut->disable(); |
| 18 | + require_once( "$IP/includes/Setup.php" ); |
| 19 | + require_once( "Attribute.php" ); |
| 20 | + require_once( "WikiDataBootstrappedMeanings.php" ); |
| 21 | + require_once( "RecordSet.php" ); |
| 22 | + require_once( "Editor.php" ); |
| 23 | + require_once( "HTMLtable.php" ); |
| 24 | + # require_once("WikiDataAPI.php"); |
| 25 | + require_once( "Transaction.php" ); |
| 26 | + require_once( "OmegaWikiEditors.php" ); |
| 27 | + require_once( "Utilities.php" ); |
| 28 | + require_once( "Wikidata.php" ); |
| 29 | + require_once( "WikiDataTables.php" ); |
| 30 | + require_once( "WikiDataGlobals.php" ); |
36 | 31 | |
37 | | - SpecialPage::addPage( new SpecialSuggest() ); |
38 | | -} |
| 32 | + $o = OmegaWikiAttributes::getInstance(); |
39 | 33 | |
40 | | -/** |
41 | | - * Creates and runs the appropriate SQL query when a combo box is clicked |
42 | | - * the combo box table is filled with the SQL query results |
43 | | - */ |
44 | | -function getSuggestions() { |
45 | | - $o = OmegaWikiAttributes::getInstance(); |
46 | | - global $wgLang; |
47 | | - global |
48 | | - $wgDefinedMeaning, |
49 | | - $wgDefinedMeaningAttributes, |
50 | | - $wgOptionAttribute, |
51 | | - $wgLinkAttribute; |
| 34 | + $dc = wdGetDataSetContext(); |
| 35 | + $search = ltrim( $wgRequest->getVal( 'search-text' ) ); |
| 36 | + $prefix = $wgRequest->getVal( 'prefix' ); |
| 37 | + $query = $wgRequest->getVal( 'query' ); |
| 38 | + $definedMeaningId = $wgRequest->getVal( 'definedMeaningId' ); |
| 39 | + $offset = $wgRequest->getVal( 'offset' ); |
| 40 | + $attributesLevel = $wgRequest->getVal( 'attributesLevel' ); |
| 41 | + $annotationAttributeId = $wgRequest->getVal( 'annotationAttributeId' ); |
| 42 | + $syntransId = $wgRequest->getVal( 'syntransId' ); |
| 43 | + $langCode = $wgLang->getCode(); |
52 | 44 | |
53 | | - $dc = wdGetDataSetContext(); |
54 | | - @$search = ltrim( $_GET['search-text'] ); |
55 | | - @$prefix = $_GET['prefix']; |
56 | | - @$query = $_GET['query']; |
57 | | - @$definedMeaningId = $_GET['definedMeaningId']; |
58 | | - @$offset = $_GET['offset']; |
59 | | - @$attributesLevel = $_GET['attributesLevel']; |
60 | | - @$annotationAttributeId = $_GET['annotationAttributeId']; |
61 | | - $syntransId = $_GET["syntransId"]; |
62 | | - $langCode = $wgLang->getCode(); |
| 45 | + $sql = ''; |
| 46 | + $dbr = wfGetDB( DB_SLAVE ); |
63 | 47 | |
64 | | - $sql = ''; |
| 48 | + $rowText = 'spelling'; |
| 49 | + switch ( $query ) { |
| 50 | + case 'relation-type': |
| 51 | + $sqlActual = $this->getSQLForCollectionOfType( 'RELT', $langCode ); |
| 52 | + $sqlFallback = $this->getSQLForCollectionOfType( 'RELT', 'en' ); |
| 53 | + $sql = $this->constructSQLWithFallback( $sqlActual, $sqlFallback, array( "member_mid", "spelling", "collection_mid" ) ); |
| 54 | + break; |
| 55 | + case 'class': |
| 56 | + // constructSQLWithFallback is a bit broken in this case, showing several time the same lines |
| 57 | + // so : not using it. The English fall back has been included in the SQL query |
| 58 | + $sql = $this->getSQLForClasses( $langCode ); |
| 59 | + break; |
| 60 | + case $wgDefinedMeaningAttributes: |
| 61 | + $sql = $this->getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, 'DM' ); |
| 62 | + break; |
| 63 | + case 'text-attribute': |
| 64 | + $sql = $this->getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, 'TEXT' ); |
| 65 | + break; |
| 66 | + case 'translated-text-attribute': |
| 67 | + $sql = $this->getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, 'TRNS' ); |
| 68 | + break; |
| 69 | + case $wgLinkAttribute: |
| 70 | + $sql = $this->getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, 'URL' ); |
| 71 | + break; |
| 72 | + case $wgOptionAttribute: |
| 73 | + $sql = $this->getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, 'OPTN' ); |
| 74 | + break; |
| 75 | + case 'language': |
| 76 | + require_once( 'languages.php' ); |
| 77 | + $sql = $this->getSQLForLanguageNames( $langCode ); |
| 78 | + $rowText = 'language_name'; |
| 79 | + break; |
| 80 | + case $wgDefinedMeaning: |
| 81 | + $sql = |
| 82 | + "SELECT {$dc}_syntrans.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling AS spelling, {$dc}_expression.language_id AS language_id " . |
| 83 | + " FROM {$dc}_expression, {$dc}_syntrans " . |
| 84 | + " WHERE {$dc}_expression.expression_id={$dc}_syntrans.expression_id " . |
| 85 | + " AND {$dc}_syntrans.identical_meaning=1 " . |
| 86 | + " AND " . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
| 87 | + " AND " . getLatestTransactionRestriction( "{$dc}_expression" ); |
| 88 | + break; |
| 89 | + case 'class-attributes-level': |
| 90 | + $sql = $this->getSQLForLevels( $langCode ); |
| 91 | + break; |
| 92 | + case 'collection': |
| 93 | + $sql = $this->getSQLForCollection( $langCode ); |
| 94 | + break; |
| 95 | + case 'transaction': |
| 96 | + $sql = |
| 97 | + "SELECT transaction_id, user_id, user_ip, " . |
| 98 | + " CONCAT(SUBSTRING(timestamp, 1, 4), '-', SUBSTRING(timestamp, 5, 2), '-', SUBSTRING(timestamp, 7, 2), ' '," . |
| 99 | + " SUBSTRING(timestamp, 9, 2), ':', SUBSTRING(timestamp, 11, 2), ':', SUBSTRING(timestamp, 13, 2)) AS time, comment" . |
| 100 | + " FROM {$dc}_transactions WHERE 1"; |
65 | 101 | |
66 | | - $dbr = wfGetDB( DB_SLAVE ); |
67 | | - $rowText = 'spelling'; |
68 | | - switch ( $query ) { |
69 | | - case 'relation-type': |
70 | | - $sqlActual = getSQLForCollectionOfType( 'RELT', $langCode ); |
71 | | - $sqlFallback = getSQLForCollectionOfType( 'RELT', 'en' ); |
72 | | - $sql = constructSQLWithFallback( $sqlActual, $sqlFallback, array( "member_mid", "spelling", "collection_mid" ) ); |
73 | | - break; |
74 | | - case 'class': |
75 | | - // constructSQLWithFallback is a bit broken in this case, showing several time the same lines |
76 | | - // so : not using it. The English fall back has been included in the SQL query |
77 | | - $sql = getSQLForClasses( $langCode ); |
78 | | - break; |
79 | | - case "$wgDefinedMeaningAttributes": |
80 | | - $sql = getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, 'DM' ); |
81 | | - break; |
82 | | - case 'text-attribute': |
83 | | - $sql = getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, 'TEXT' ); |
84 | | - break; |
85 | | - case 'translated-text-attribute': |
86 | | - $sql = getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, 'TRNS' ); |
87 | | - break; |
88 | | - case "$wgLinkAttribute": |
89 | | - $sql = getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, 'URL' ); |
90 | | - break; |
91 | | - case "$wgOptionAttribute": |
92 | | - $sql = getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, 'OPTN' ); |
93 | | - break; |
94 | | - case 'language': |
95 | | - require_once( 'languages.php' ); |
96 | | - $sql = getSQLForLanguageNames( $langCode ); |
97 | | - $rowText = 'language_name'; |
98 | | - break; |
99 | | - case "$wgDefinedMeaning": |
100 | | - $sql = |
101 | | - "SELECT {$dc}_syntrans.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling AS spelling, {$dc}_expression.language_id AS language_id " . |
102 | | - " FROM {$dc}_expression, {$dc}_syntrans " . |
103 | | - " WHERE {$dc}_expression.expression_id={$dc}_syntrans.expression_id " . |
104 | | - " AND {$dc}_syntrans.identical_meaning=1 " . |
105 | | - " AND " . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
106 | | - " AND " . getLatestTransactionRestriction( "{$dc}_expression" ); |
107 | | - break; |
108 | | - case 'class-attributes-level': |
109 | | - $sql = getSQLForLevels( $langCode ); |
110 | | - break; |
111 | | - case 'collection': |
112 | | - $sql = getSQLForCollection( $langCode ); |
113 | | - break; |
114 | | - case 'transaction': |
115 | | - $sql = |
116 | | - "SELECT transaction_id, user_id, user_ip, " . |
117 | | - " CONCAT(SUBSTRING(timestamp, 1, 4), '-', SUBSTRING(timestamp, 5, 2), '-', SUBSTRING(timestamp, 7, 2), ' '," . |
118 | | - " SUBSTRING(timestamp, 9, 2), ':', SUBSTRING(timestamp, 11, 2), ':', SUBSTRING(timestamp, 13, 2)) AS time, comment" . |
119 | | - " FROM {$dc}_transactions WHERE 1"; |
120 | | - |
121 | | - $rowText = "CONCAT(SUBSTRING(timestamp, 1, 4), '-', SUBSTRING(timestamp, 5, 2), '-', SUBSTRING(timestamp, 7, 2), ' '," . |
122 | | - " SUBSTRING(timestamp, 9, 2), ':', SUBSTRING(timestamp, 11, 2), ':', SUBSTRING(timestamp, 13, 2))"; |
123 | | - break; |
124 | | - } |
| 102 | + $rowText = "CONCAT(SUBSTRING(timestamp, 1, 4), '-', SUBSTRING(timestamp, 5, 2), '-', SUBSTRING(timestamp, 7, 2), ' '," . |
| 103 | + " SUBSTRING(timestamp, 9, 2), ':', SUBSTRING(timestamp, 11, 2), ':', SUBSTRING(timestamp, 13, 2))"; |
| 104 | + break; |
| 105 | + } |
125 | 106 | |
126 | | - if ( $search != '' ) { |
| 107 | + if ( $search != '' ) { |
| 108 | + if ( $query == 'transaction' ) |
| 109 | + $searchCondition = " AND $rowText LIKE " . $dbr->addQuotes( "%$search%" ); |
| 110 | + else if ( $query == 'class' ) |
| 111 | + $searchCondition = " AND $rowText LIKE " . $dbr->addQuotes( "$search%" ); |
| 112 | + else if ( $query == "$wgDefinedMeaningAttributes" or // should be 'relation-type' in html, there is a bug I cannot find |
| 113 | + $query == "$wgLinkAttribute" or |
| 114 | + $query == "$wgOptionAttribute" or |
| 115 | + $query == 'translated-text-attribute' or |
| 116 | + $query == 'text-attribute' ) |
| 117 | + $searchCondition = " HAVING $rowText LIKE " . $dbr->addQuotes( "$search%" ); |
| 118 | + else if ( $query == 'language' ) |
| 119 | + $searchCondition = " HAVING $rowText LIKE " . $dbr->addQuotes( "%$search%" ); |
| 120 | + else if ( $query == 'relation-type' ) // not sure in which case 'relation-type' happens... |
| 121 | + $searchCondition = " WHERE $rowText LIKE " . $dbr->addQuotes( "$search%" ); |
| 122 | + else |
| 123 | + $searchCondition = " AND $rowText LIKE " . $dbr->addQuotes( "$search%" ); |
| 124 | + } |
| 125 | + else |
| 126 | + $searchCondition = ""; |
| 127 | + |
127 | 128 | if ( $query == 'transaction' ) |
128 | | - $searchCondition = " AND $rowText LIKE " . $dbr->addQuotes( "%$search%" ); |
129 | | - else if ( $query == 'class' ) |
130 | | - $searchCondition = " AND $rowText LIKE " . $dbr->addQuotes( "$search%" ); |
131 | | - else if ( $query == "$wgDefinedMeaningAttributes" or // should be 'relation-type' in html, there is a bug I cannot find |
132 | | - $query == "$wgLinkAttribute" or |
133 | | - $query == "$wgOptionAttribute" or |
134 | | - $query == 'translated-text-attribute' or |
135 | | - $query == 'text-attribute' ) |
136 | | - $searchCondition = " HAVING $rowText LIKE " . $dbr->addQuotes( "$search%" ); |
137 | | - else if ( $query == 'language' ) |
138 | | - $searchCondition = " HAVING $rowText LIKE " . $dbr->addQuotes( "%$search%" ); |
139 | | - else if ( $query == 'relation-type' ) // not sure in which case 'relation-type' happens... |
140 | | - $searchCondition = " WHERE $rowText LIKE " . $dbr->addQuotes( "$search%" ); |
| 129 | + $orderBy = 'transaction_id DESC'; |
141 | 130 | else |
142 | | - $searchCondition = " AND $rowText LIKE " . $dbr->addQuotes( "$search%" ); |
143 | | - } |
144 | | - else |
145 | | - $searchCondition = ""; |
| 131 | + $orderBy = $rowText; |
146 | 132 | |
147 | | - if ( $query == 'transaction' ) |
148 | | - $orderBy = 'transaction_id DESC'; |
149 | | - else |
150 | | - $orderBy = $rowText; |
| 133 | + $sql .= $searchCondition . " ORDER BY $orderBy LIMIT "; |
151 | 134 | |
152 | | - $sql .= $searchCondition . " ORDER BY $orderBy LIMIT "; |
| 135 | + if ( $offset > 0 ) |
| 136 | + $sql .= " $offset, "; |
| 137 | + |
| 138 | + // print only 10 results |
| 139 | + $sql .= "10"; |
153 | 140 | |
154 | | - if ( $offset > 0 ) |
155 | | - $sql .= " $offset, "; |
156 | | - |
157 | | - // print only 10 results |
158 | | - $sql .= "10"; |
| 141 | + # == Actual query here |
| 142 | + // wfdebug("]]]".$sql."\n"); |
| 143 | + $queryResult = $dbr->query( $sql ); |
159 | 144 | |
160 | | - # == Actual query here |
161 | | - // wfdebug("]]]".$sql."\n"); |
162 | | - $queryResult = $dbr->query( $sql ); |
| 145 | + $o->id = new Attribute( "id", wfMsg( 'ow_ID' ), "id" ); |
163 | 146 | |
164 | | - $o->id = new Attribute( "id", wfMsg( 'ow_ID' ), "id" ); |
165 | | - |
166 | | - # == Process query |
167 | | - switch( $query ) { |
168 | | - case 'relation-type': |
169 | | - list( $recordSet, $editor ) = getRelationTypeAsRecordSet( $queryResult ); |
170 | | - break; |
171 | | - case 'class': |
172 | | - list( $recordSet, $editor ) = getClassAsRecordSet( $queryResult ); |
173 | | - break; |
174 | | - case "$wgDefinedMeaningAttributes": |
175 | | - list( $recordSet, $editor ) = getDefinedMeaningAttributeAsRecordSet( $queryResult ); |
176 | | - break; |
177 | | - case 'text-attribute': |
178 | | - list( $recordSet, $editor ) = getTextAttributeAsRecordSet( $queryResult ); |
179 | | - break; |
180 | | - case 'translated-text-attribute': |
181 | | - list( $recordSet, $editor ) = getTranslatedTextAttributeAsRecordSet( $queryResult ); |
182 | | - break; |
183 | | - case "$wgLinkAttribute": |
184 | | - list( $recordSet, $editor ) = getLinkAttributeAsRecordSet( $queryResult ); |
185 | | - break; |
186 | | - case "$wgOptionAttribute": |
187 | | - list( $recordSet, $editor ) = getOptionAttributeAsRecordSet( $queryResult ); |
188 | | - break; |
189 | | - case "$wgDefinedMeaning": |
190 | | - list( $recordSet, $editor ) = getDefinedMeaningAsRecordSet( $queryResult ); |
191 | | - break; |
192 | | - case 'class-attributes-level': |
193 | | - list( $recordSet, $editor ) = getClassAttributeLevelAsRecordSet( $queryResult ); |
194 | | - break; |
195 | | - case 'collection': |
196 | | - list( $recordSet, $editor ) = getCollectionAsRecordSet( $queryResult ); |
197 | | - break; |
198 | | - case 'language': |
199 | | - list( $recordSet, $editor ) = getLanguageAsRecordSet( $queryResult ); |
200 | | - break; |
201 | | - case 'transaction': |
202 | | - list( $recordSet, $editor ) = getTransactionAsRecordSet( $queryResult ); |
203 | | - break; |
204 | | - } |
205 | | - ob_start(); |
206 | | - var_dump( $queryResult ); |
207 | | - var_dump( $recordSet ); |
208 | | - var_dump( $editor ); |
209 | | - wfDebug( ob_get_contents() ); |
210 | | - ob_end_clean(); |
| 147 | + # == Process query |
| 148 | + switch( $query ) { |
| 149 | + case 'relation-type': |
| 150 | + list( $recordSet, $editor ) = $this->getRelationTypeAsRecordSet( $queryResult ); |
| 151 | + break; |
| 152 | + case 'class': |
| 153 | + list( $recordSet, $editor ) = $this->getClassAsRecordSet( $queryResult ); |
| 154 | + break; |
| 155 | + case "$wgDefinedMeaningAttributes": |
| 156 | + list( $recordSet, $editor ) = $this->getDefinedMeaningAttributeAsRecordSet( $queryResult ); |
| 157 | + break; |
| 158 | + case 'text-attribute': |
| 159 | + list( $recordSet, $editor ) = $this->getTextAttributeAsRecordSet( $queryResult ); |
| 160 | + break; |
| 161 | + case 'translated-text-attribute': |
| 162 | + list( $recordSet, $editor ) = $this->getTranslatedTextAttributeAsRecordSet( $queryResult ); |
| 163 | + break; |
| 164 | + case "$wgLinkAttribute": |
| 165 | + list( $recordSet, $editor ) = $this->getLinkAttributeAsRecordSet( $queryResult ); |
| 166 | + break; |
| 167 | + case "$wgOptionAttribute": |
| 168 | + list( $recordSet, $editor ) = $this->getOptionAttributeAsRecordSet( $queryResult ); |
| 169 | + break; |
| 170 | + case "$wgDefinedMeaning": |
| 171 | + list( $recordSet, $editor ) = $this->getDefinedMeaningAsRecordSet( $queryResult ); |
| 172 | + break; |
| 173 | + case 'class-attributes-level': |
| 174 | + list( $recordSet, $editor ) = $this->getClassAttributeLevelAsRecordSet( $queryResult ); |
| 175 | + break; |
| 176 | + case 'collection': |
| 177 | + list( $recordSet, $editor ) = $this->getCollectionAsRecordSet( $queryResult ); |
| 178 | + break; |
| 179 | + case 'language': |
| 180 | + list( $recordSet, $editor ) = $this->getLanguageAsRecordSet( $queryResult ); |
| 181 | + break; |
| 182 | + case 'transaction': |
| 183 | + list( $recordSet, $editor ) = $this->getTransactionAsRecordSet( $queryResult ); |
| 184 | + break; |
| 185 | + } |
211 | 186 | |
212 | | - $output = $editor->view( new IdStack( $prefix . 'table' ), $recordSet ); |
213 | | - // $output="<table><tr><td>HELLO ERIK!</td></tr></table>"; |
214 | | - // wfDebug($output); |
215 | | - return $output; |
216 | | -} |
| 187 | + ob_start(); |
| 188 | + var_dump( $queryResult ); |
| 189 | + var_dump( $recordSet ); |
| 190 | + var_dump( $editor ); |
| 191 | + wfDebug( ob_get_contents() ); |
| 192 | + ob_end_clean(); |
217 | 193 | |
218 | | -# Constructs a new SQL query from 2 other queries such that if a field exists |
219 | | -# in the fallback query, but not in the actual query, the field from the |
220 | | -# fallback query will be returned. Fields not in the fallback are ignored. |
221 | | -# You will need to state which fields in your query need to be returned. |
222 | | -# As a (minor) hack, the 0th element of $fields is assumed to be the key field. |
223 | | -function constructSQLWithFallback( $actual_query, $fallback_query, $fields ) { |
| 194 | + $output = $editor->view( new IdStack( $prefix . 'table' ), $recordSet ); |
| 195 | + // $output="<table><tr><td>HELLO ERIK!</td></tr></table>"; |
| 196 | + // wfDebug($output); |
| 197 | + echo $output; |
| 198 | + } |
224 | 199 | |
225 | | - # if ($actual_query==$fallback_query) |
226 | | - # return $actual_query; |
| 200 | + /** Constructs a new SQL query from 2 other queries such that if a field exists |
| 201 | + * in the fallback query, but not in the actual query, the field from the |
| 202 | + * fallback query will be returned. Fields not in the fallback are ignored. |
| 203 | + * You will need to state which fields in your query need to be returned. |
| 204 | + * As a (minor) hack, the 0th element of $fields is assumed to be the key field. |
| 205 | + */ |
| 206 | + private function constructSQLWithFallback( $actual_query, $fallback_query, $fields ) { |
227 | 207 | |
228 | | - $sql = "SELECT * FROM (SELECT "; |
| 208 | + # if ($actual_query==$fallback_query) |
| 209 | + # return $actual_query; |
229 | 210 | |
230 | | - $sql_with_comma = $sql; |
231 | | - foreach ( $fields as $field ) { |
232 | | - $sql = $sql_with_comma; |
233 | | - $sql .= "COALESCE(actual.$field, fallback.$field) as $field"; |
| 211 | + $sql = "SELECT * FROM (SELECT "; |
| 212 | + |
234 | 213 | $sql_with_comma = $sql; |
235 | | - $sql_with_comma .= ", "; |
236 | | - } |
237 | | - |
238 | | - $sql .= " FROM "; |
239 | | - $sql .= " ( $fallback_query ) AS fallback"; |
240 | | - $sql .= " LEFT JOIN "; |
241 | | - $sql .= " ( $actual_query ) AS actual"; |
| 214 | + foreach ( $fields as $field ) { |
| 215 | + $sql = $sql_with_comma; |
| 216 | + $sql .= "COALESCE(actual.$field, fallback.$field) as $field"; |
| 217 | + $sql_with_comma = $sql; |
| 218 | + $sql_with_comma .= ", "; |
| 219 | + } |
| 220 | + |
| 221 | + $sql .= " FROM "; |
| 222 | + $sql .= " ( $fallback_query ) AS fallback"; |
| 223 | + $sql .= " LEFT JOIN "; |
| 224 | + $sql .= " ( $actual_query ) AS actual"; |
242 | 225 | |
243 | | - $field0 = $fields[0]; # slightly presumptuous |
244 | | - $sql .= " ON actual.$field0 = fallback.$field0"; |
245 | | - $sql .= ") as coalesced"; |
246 | | - return $sql; |
247 | | -} |
| 226 | + $field0 = $fields[0]; # slightly presumptuous |
| 227 | + $sql .= " ON actual.$field0 = fallback.$field0"; |
| 228 | + $sql .= ") as coalesced"; |
| 229 | + return $sql; |
| 230 | + } |
248 | 231 | |
249 | | -/** |
250 | | - * Returns the list of attributes of a given $attributesType (DM, TEXT, TRNS, URL, OPTN) |
251 | | - * in the user language or in English |
252 | | - * |
253 | | - * @param $language the 2 letter wikimedia code |
254 | | - */ |
| 232 | + /** |
| 233 | + * Returns the list of attributes of a given $attributesType (DM, TEXT, TRNS, URL, OPTN) |
| 234 | + * in the user language or in English |
| 235 | + * |
| 236 | + * @param $language the 2 letter wikimedia code |
| 237 | + */ |
| 238 | + private function getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, $attributesType ) { |
| 239 | + global $wgDefaultClassMids, $wgLang; |
255 | 240 | |
256 | | -function getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, $attributesType ) { |
| 241 | + $dc = wdGetDataSetContext(); |
| 242 | + $dbr = wfGetDB( DB_SLAVE ); |
257 | 243 | |
258 | | - global $wgDefaultClassMids, $wgLang; |
| 244 | + $language = $wgLang->getCode() ; |
| 245 | + $lng = ' ( SELECT language_id FROM language WHERE wikimedia_key = ' . $dbr->addQuotes( $language ) . ' ) '; |
259 | 246 | |
260 | | - $dc = wdGetDataSetContext(); |
261 | | - $dbr = wfGetDB( DB_SLAVE ); |
| 247 | + $classMids = $wgDefaultClassMids ; |
262 | 248 | |
263 | | - $language = $wgLang->getCode() ; |
264 | | - $lng = ' ( SELECT language_id FROM language WHERE wikimedia_key = ' . $dbr->addQuotes( $language ) . ' ) '; |
265 | | - |
266 | | - $classMids = $wgDefaultClassMids ; |
267 | | - |
268 | | - if ( $syntransId != 0 ) { |
269 | | - // find the language of the syntrans and add attributes of that language by adding the language DM to the list of default classes |
270 | | - // this first query returns the language_id |
271 | | - $sql = 'SELECT language_id' . |
| 249 | + if ( $syntransId != 0 ) { |
| 250 | + // find the language of the syntrans and add attributes of that language by adding the language DM to the list of default classes |
| 251 | + // this first query returns the language_id |
| 252 | + $sql = 'SELECT language_id' . |
272 | 253 | " FROM {$dc}_syntrans" . |
273 | 254 | " JOIN {$dc}_expression ON {$dc}_expression.expression_id = {$dc}_syntrans.expression_id" . |
274 | 255 | " WHERE {$dc}_syntrans.syntrans_sid = " . $syntransId . |
275 | 256 | ' AND ' . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
276 | 257 | ' AND ' . getLatestTransactionRestriction( "{$dc}_expression" ); |
277 | | - $lang_res = $dbr->query( $sql ); |
278 | | - $language_id = $dbr->fetchObject( $lang_res )->language_id; |
| 258 | + $lang_res = $dbr->query( $sql ); |
| 259 | + $language_id = $dbr->fetchObject( $lang_res )->language_id; |
279 | 260 | |
280 | | - // this second query finds the DM number for a given language_id |
281 | | - // 145264 is the collection_id of the "ISO 639-3 codes" collection |
282 | | - $sql = "SELECT member_mid FROM {$dc}_collection_contents, language" . |
| 261 | + // this second query finds the DM number for a given language_id |
| 262 | + // 145264 is the collection_id of the "ISO 639-3 codes" collection |
| 263 | + $sql = "SELECT member_mid FROM {$dc}_collection_contents, language" . |
283 | 264 | " WHERE language.language_id = $language_id" . |
284 | 265 | " AND {$dc}_collection_contents.collection_id = 145264" . |
285 | 266 | " AND language.iso639_3 = {$dc}_collection_contents.internal_member_id" . |
286 | 267 | ' AND ' . getLatestTransactionRestriction( "{$dc}_collection_contents" ); |
287 | | - $lang_res = $dbr->query( $sql ); |
288 | | - $language_dm_id = $dbr->fetchObject( $lang_res )->member_mid; |
| 268 | + $lang_res = $dbr->query( $sql ); |
| 269 | + $language_dm_id = $dbr->fetchObject( $lang_res )->member_mid; |
289 | 270 | |
290 | | - $classMids = array_merge ( $wgDefaultClassMids , array($language_dm_id) ) ; |
291 | | - } |
| 271 | + $classMids = array_merge ( $wgDefaultClassMids , array($language_dm_id) ) ; |
| 272 | + } |
292 | 273 | |
293 | | - if ( count( $classMids ) > 0 ) |
294 | | - $defaultClassRestriction = " OR {$dc}_class_attributes.class_mid IN (" . join( $classMids, ", " ) . ")"; |
295 | | - else |
296 | | - $defaultClassRestriction = ""; |
| 274 | + if ( count( $classMids ) > 0 ) |
| 275 | + $defaultClassRestriction = " OR {$dc}_class_attributes.class_mid IN (" . join( $classMids, ", " ) . ")"; |
| 276 | + else |
| 277 | + $defaultClassRestriction = ""; |
297 | 278 | |
298 | | - $filteredAttributesRestriction = getFilteredAttributesRestriction( $annotationAttributeId ); |
| 279 | + $filteredAttributesRestriction = $this->getFilteredAttributesRestriction( $annotationAttributeId ); |
299 | 280 | |
300 | | - $sql = |
| 281 | + $sql = |
301 | 282 | 'SELECT attribute_mid, MAX(spelling) as spelling FROM (' . |
302 | 283 | 'SELECT attribute_mid, spelling' . |
303 | 284 | " FROM {$dc}_bootstrapped_defined_meanings, {$dc}_class_attributes, {$dc}_syntrans, {$dc}_expression" . |
— | — | @@ -307,454 +288,454 @@ |
308 | 289 | " AND {$dc}_expression.expression_id = {$dc}_syntrans.expression_id" . |
309 | 290 | $filteredAttributesRestriction . " "; |
310 | 291 | |
311 | | - $sql .= |
312 | | - " AND ( language_id=$lng " . |
313 | | - ' OR ( ' . |
314 | | - ' language_id=85 ' . |
315 | | - " AND {$dc}_syntrans.defined_meaning_id NOT IN ( SELECT defined_meaning_id FROM {$dc}_syntrans synt, {$dc}_expression exp WHERE exp.expression_id = synt.expression_id AND exp.language_id=$lng ) " . |
316 | | - ' ) ) ' ; |
| 292 | + $sql .= |
| 293 | + " AND ( language_id=$lng " . |
| 294 | + ' OR ( ' . |
| 295 | + ' language_id=85 ' . |
| 296 | + " AND {$dc}_syntrans.defined_meaning_id NOT IN ( SELECT defined_meaning_id FROM {$dc}_syntrans synt, {$dc}_expression exp WHERE exp.expression_id = synt.expression_id AND exp.language_id=$lng ) " . |
| 297 | + ' ) ) ' ; |
317 | 298 | |
318 | | - $sql .= |
319 | | - ' AND ' . getLatestTransactionRestriction( "{$dc}_class_attributes" ) . |
320 | | - ' AND ' . getLatestTransactionRestriction( "{$dc}_expression" ) . |
321 | | - ' AND ' . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
322 | | - " AND ({$dc}_class_attributes.class_mid IN (" . |
| 299 | + $sql .= |
| 300 | + ' AND ' . getLatestTransactionRestriction( "{$dc}_class_attributes" ) . |
| 301 | + ' AND ' . getLatestTransactionRestriction( "{$dc}_expression" ) . |
| 302 | + ' AND ' . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
| 303 | + " AND ({$dc}_class_attributes.class_mid IN (" . |
323 | 304 | ' SELECT class_mid ' . |
324 | 305 | " FROM {$dc}_class_membership" . |
325 | 306 | " WHERE {$dc}_class_membership.class_member_mid = " . $definedMeaningId . |
326 | 307 | ' AND ' . getLatestTransactionRestriction( "{$dc}_class_membership" ) . |
327 | 308 | ' )' . |
328 | 309 | $defaultClassRestriction . |
329 | | - ')'; |
| 310 | + ')'; |
330 | 311 | |
331 | | - $sql .= ') AS filtered GROUP BY attribute_mid'; |
| 312 | + $sql .= ') AS filtered GROUP BY attribute_mid'; |
332 | 313 | |
333 | | - return $sql ; |
334 | | -} |
| 314 | + return $sql; |
| 315 | + } |
335 | 316 | |
336 | | -function getPropertyToColumnFilterForAttribute( $annotationAttributeId ) { |
337 | | - global |
338 | | - $wgPropertyToColumnFilters; |
| 317 | + private function getPropertyToColumnFilterForAttribute( $annotationAttributeId ) { |
| 318 | + global $wgPropertyToColumnFilters; |
339 | 319 | |
340 | | - $i = 0; |
341 | | - $result = null; |
| 320 | + $i = 0; |
| 321 | + $result = null; |
342 | 322 | |
343 | | - while ( $result == null && $i < count( $wgPropertyToColumnFilters ) ) |
344 | | - if ( $wgPropertyToColumnFilters[$i]->getAttribute()->id == $annotationAttributeId ) |
345 | | - $result = $wgPropertyToColumnFilters[$i]; |
346 | | - else |
347 | | - $i++; |
| 323 | + while ( $result == null && $i < count( $wgPropertyToColumnFilters ) ) |
| 324 | + if ( $wgPropertyToColumnFilters[$i]->getAttribute()->id == $annotationAttributeId ) |
| 325 | + $result = $wgPropertyToColumnFilters[$i]; |
| 326 | + else |
| 327 | + $i++; |
348 | 328 | |
349 | | - return $result; |
350 | | -} |
| 329 | + return $result; |
| 330 | + } |
351 | 331 | |
352 | | -function getFilteredAttributes( $annotationAttributeId ) { |
353 | | - $propertyToColumnFilter = getPropertyToColumnFilterForAttribute( $annotationAttributeId ); |
| 332 | + private function getFilteredAttributes( $annotationAttributeId ) { |
| 333 | + $propertyToColumnFilter = $this->getPropertyToColumnFilterForAttribute( $annotationAttributeId ); |
354 | 334 | |
355 | | - if ( $propertyToColumnFilter != null ) |
356 | | - return $propertyToColumnFilter->attributeIDs; |
357 | | - else |
358 | | - return array(); |
359 | | -} |
| 335 | + if ( $propertyToColumnFilter != null ) |
| 336 | + return $propertyToColumnFilter->attributeIDs; |
| 337 | + else |
| 338 | + return array(); |
| 339 | + } |
360 | 340 | |
361 | | -function getAllFilteredAttributes() { |
362 | | - global |
363 | | - $wgPropertyToColumnFilters; |
| 341 | + private function getAllFilteredAttributes() { |
| 342 | + global $wgPropertyToColumnFilters; |
364 | 343 | |
365 | | - $result = array(); |
| 344 | + $result = array(); |
366 | 345 | |
367 | | - foreach ( $wgPropertyToColumnFilters as $propertyToColumnFilter ) |
368 | | - $result = array_merge( $result, $propertyToColumnFilter->attributeIDs ); |
| 346 | + foreach ( $wgPropertyToColumnFilters as $propertyToColumnFilter ) |
| 347 | + $result = array_merge( $result, $propertyToColumnFilter->attributeIDs ); |
369 | 348 | |
370 | | - return $result; |
371 | | -} |
| 349 | + return $result; |
| 350 | + } |
372 | 351 | |
373 | | -function getFilteredAttributesRestriction( $annotationAttributeId ) { |
374 | | - $dc = wdGetDataSetContext(); |
| 352 | + private function getFilteredAttributesRestriction( $annotationAttributeId ) { |
| 353 | + $dc = wdGetDataSetContext(); |
375 | 354 | |
376 | | - $propertyToColumnFilter = getPropertyToColumnFilterForAttribute( $annotationAttributeId ); |
| 355 | + $propertyToColumnFilter = $this->getPropertyToColumnFilterForAttribute( $annotationAttributeId ); |
377 | 356 | |
378 | | - if ( $propertyToColumnFilter != null ) { |
379 | | - $filteredAttributes = $propertyToColumnFilter->attributeIDs; |
| 357 | + if ( $propertyToColumnFilter != null ) { |
| 358 | + $filteredAttributes = $propertyToColumnFilter->attributeIDs; |
380 | 359 | |
381 | | - if ( count( $filteredAttributes ) > 0 ) |
382 | | - $result = " AND {$dc}_class_attributes.attribute_mid IN (" . join( $filteredAttributes, ", " ) . ")"; |
383 | | - else |
384 | | - $result = " AND 0 "; |
385 | | - } |
386 | | - else { |
387 | | - $allFilteredAttributes = getAllFilteredAttributes(); |
| 360 | + if ( count( $filteredAttributes ) > 0 ) |
| 361 | + $result = " AND {$dc}_class_attributes.attribute_mid IN (" . join( $filteredAttributes, ", " ) . ")"; |
| 362 | + else |
| 363 | + $result = " AND 0 "; |
| 364 | + } |
| 365 | + else { |
| 366 | + $allFilteredAttributes = $this->getAllFilteredAttributes(); |
388 | 367 | |
389 | | - if ( count( $allFilteredAttributes ) > 0 ) |
390 | | - $result = " AND {$dc}_class_attributes.attribute_mid NOT IN (" . join( $allFilteredAttributes, ", " ) . ")"; |
391 | | - else |
392 | | - $result = ""; |
| 368 | + if ( count( $allFilteredAttributes ) > 0 ) |
| 369 | + $result = " AND {$dc}_class_attributes.attribute_mid NOT IN (" . join( $allFilteredAttributes, ", " ) . ")"; |
| 370 | + else |
| 371 | + $result = ""; |
| 372 | + } |
| 373 | + |
| 374 | + return $result; |
393 | 375 | } |
394 | | - |
395 | | - return $result; |
396 | | -} |
397 | 376 | |
398 | 377 | |
399 | | -/** |
400 | | - * Returns the name of all classes and their spelling in the user language or in English |
401 | | - * |
402 | | - * @param $language the 2 letter wikimedia code |
403 | | - */ |
404 | | -function getSQLForClasses( $language ) { |
405 | | - $dc = wdGetDataSetContext(); |
| 378 | + /** |
| 379 | + * Returns the name of all classes and their spelling in the user language or in English |
| 380 | + * |
| 381 | + * @param $language the 2 letter wikimedia code |
| 382 | + */ |
| 383 | + private function getSQLForClasses( $language ) { |
| 384 | + $dc = wdGetDataSetContext(); |
406 | 385 | |
407 | | - $dbr = wfGetDB( DB_SLAVE ); |
408 | | - $lng = '( SELECT language_id FROM language WHERE wikimedia_key = ' . $dbr->addQuotes( $language ) . ' )'; |
| 386 | + $dbr = wfGetDB( DB_SLAVE ); |
| 387 | + $lng = '( SELECT language_id FROM language WHERE wikimedia_key = ' . $dbr->addQuotes( $language ) . ' )'; |
409 | 388 | |
410 | | - // exp.spelling, txt.text_text |
411 | | - $sql = "SELECT member_mid, spelling " . |
412 | | - " FROM {$dc}_collection_contents col_contents, {$dc}_collection col, {$dc}_syntrans synt," . |
413 | | - " {$dc}_expression exp, {$dc}_defined_meaning dm" . |
414 | | - " WHERE col.collection_type='CLAS' " . |
415 | | - " AND col_contents.collection_id = col.collection_id " . |
416 | | - " AND synt.defined_meaning_id = col_contents.member_mid " . |
417 | | -// " AND synt.identical_meaning=1 " . |
418 | | - " AND exp.expression_id = synt.expression_id " . |
419 | | - " AND dm.defined_meaning_id = synt.defined_meaning_id " . |
420 | | - " AND ( " . |
421 | | - " exp.language_id=$lng " . |
422 | | - " OR (" . |
423 | | - " exp.language_id=85 " . |
424 | | - " AND dm.defined_meaning_id NOT IN " . |
425 | | - " ( SELECT defined_meaning_id FROM {$dc}_syntrans synt_bis, {$dc}_expression exp_bis " . |
426 | | - " WHERE exp_bis.expression_id = synt_bis.expression_id AND exp_bis.language_id=$lng " . |
427 | | - " AND synt_bis.remove_transaction_id IS NULL AND exp_bis.remove_transaction_id IS NULL ) " . |
| 389 | + // exp.spelling, txt.text_text |
| 390 | + $sql = "SELECT member_mid, spelling " . |
| 391 | + " FROM {$dc}_collection_contents col_contents, {$dc}_collection col, {$dc}_syntrans synt," . |
| 392 | + " {$dc}_expression exp, {$dc}_defined_meaning dm" . |
| 393 | + " WHERE col.collection_type='CLAS' " . |
| 394 | + " AND col_contents.collection_id = col.collection_id " . |
| 395 | + " AND synt.defined_meaning_id = col_contents.member_mid " . |
| 396 | +// " AND synt.identical_meaning=1 " . |
| 397 | + " AND exp.expression_id = synt.expression_id " . |
| 398 | + " AND dm.defined_meaning_id = synt.defined_meaning_id " . |
| 399 | + " AND ( " . |
| 400 | + " exp.language_id=$lng " . |
| 401 | + " OR (" . |
| 402 | + " exp.language_id=85 " . |
| 403 | + " AND dm.defined_meaning_id NOT IN " . |
| 404 | + " ( SELECT defined_meaning_id FROM {$dc}_syntrans synt_bis, {$dc}_expression exp_bis " . |
| 405 | + " WHERE exp_bis.expression_id = synt_bis.expression_id AND exp_bis.language_id=$lng " . |
| 406 | + " AND synt_bis.remove_transaction_id IS NULL AND exp_bis.remove_transaction_id IS NULL ) " . |
| 407 | + " ) " . |
428 | 408 | " ) " . |
429 | | - " ) " . |
430 | | - " AND " . getLatestTransactionRestriction( "col" ) . |
431 | | - " AND " . getLatestTransactionRestriction( "col_contents" ) . |
432 | | - " AND " . getLatestTransactionRestriction( "synt" ) . |
433 | | - " AND " . getLatestTransactionRestriction( "exp" ) . |
434 | | - " AND " . getLatestTransactionRestriction( "dm" ) ; |
| 409 | + " AND " . getLatestTransactionRestriction( "col" ) . |
| 410 | + " AND " . getLatestTransactionRestriction( "col_contents" ) . |
| 411 | + " AND " . getLatestTransactionRestriction( "synt" ) . |
| 412 | + " AND " . getLatestTransactionRestriction( "exp" ) . |
| 413 | + " AND " . getLatestTransactionRestriction( "dm" ) ; |
435 | 414 | |
436 | | - return $sql; |
437 | | -} |
| 415 | + return $sql; |
| 416 | + } |
438 | 417 | |
439 | | -function getSQLForCollectionOfType( $collectionType, $language = "<ANY>" ) { |
440 | | - $dc = wdGetDataSetContext(); |
441 | | - $sql = "SELECT member_mid, spelling, collection_mid " . |
442 | | - " FROM {$dc}_collection_contents, {$dc}_collection, {$dc}_syntrans, {$dc}_expression " . |
443 | | - " WHERE {$dc}_collection_contents.collection_id={$dc}_collection.collection_id " . |
444 | | - " AND {$dc}_collection.collection_type='$collectionType' " . |
445 | | - " AND {$dc}_syntrans.defined_meaning_id={$dc}_collection_contents.member_mid " . |
446 | | - " AND {$dc}_expression.expression_id={$dc}_syntrans.expression_id " . |
447 | | - " AND {$dc}_syntrans.identical_meaning=1 " . |
448 | | - " AND " . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
449 | | - " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) . |
450 | | - " AND " . getLatestTransactionRestriction( "{$dc}_collection" ) . |
451 | | - " AND " . getLatestTransactionRestriction( "{$dc}_collection_contents" ); |
452 | | - if ( $language != "<ANY>" ) { |
453 | | - $dbr = wfGetDB( DB_SLAVE ); |
454 | | - $sql .= |
455 | | - ' AND language_id=( ' . |
456 | | - ' SELECT language_id' . |
457 | | - ' FROM language' . |
458 | | - ' WHERE wikimedia_key = ' . $dbr->addQuotes( $language ) . |
459 | | - ' )'; |
| 418 | + private function getSQLForCollectionOfType( $collectionType, $language = "<ANY>" ) { |
| 419 | + $dc = wdGetDataSetContext(); |
| 420 | + $sql = "SELECT member_mid, spelling, collection_mid " . |
| 421 | + " FROM {$dc}_collection_contents, {$dc}_collection, {$dc}_syntrans, {$dc}_expression " . |
| 422 | + " WHERE {$dc}_collection_contents.collection_id={$dc}_collection.collection_id " . |
| 423 | + " AND {$dc}_collection.collection_type='$collectionType' " . |
| 424 | + " AND {$dc}_syntrans.defined_meaning_id={$dc}_collection_contents.member_mid " . |
| 425 | + " AND {$dc}_expression.expression_id={$dc}_syntrans.expression_id " . |
| 426 | + " AND {$dc}_syntrans.identical_meaning=1 " . |
| 427 | + " AND " . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
| 428 | + " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) . |
| 429 | + " AND " . getLatestTransactionRestriction( "{$dc}_collection" ) . |
| 430 | + " AND " . getLatestTransactionRestriction( "{$dc}_collection_contents" ); |
| 431 | + if ( $language != "<ANY>" ) { |
| 432 | + $dbr = wfGetDB( DB_SLAVE ); |
| 433 | + $sql .= |
| 434 | + ' AND language_id=( ' . |
| 435 | + ' SELECT language_id' . |
| 436 | + ' FROM language' . |
| 437 | + ' WHERE wikimedia_key = ' . $dbr->addQuotes( $language ) . |
| 438 | + ' )'; |
| 439 | + } |
| 440 | + return $sql; |
460 | 441 | } |
461 | | - return $sql; |
462 | | -} |
463 | 442 | |
464 | | -function getSQLForCollection( $language ) { |
465 | | - $dc = wdGetDataSetContext(); |
466 | | - $dbr = wfGetDB( DB_SLAVE ); |
467 | | - $lng = '( SELECT language_id FROM language WHERE wikimedia_key = ' . $dbr->addQuotes( $language ) . ' )'; |
| 443 | + private function getSQLForCollection( $language ) { |
| 444 | + $dc = wdGetDataSetContext(); |
| 445 | + $dbr = wfGetDB( DB_SLAVE ); |
| 446 | + $lng = '( SELECT language_id FROM language WHERE wikimedia_key = ' . $dbr->addQuotes( $language ) . ' )'; |
468 | 447 | |
469 | | - $sql = "SELECT collection_id, spelling " . |
470 | | - " FROM {$dc}_expression exp, {$dc}_collection col, {$dc}_syntrans synt, {$dc}_defined_meaning dm " . |
471 | | - " WHERE exp.expression_id=synt.expression_id " . |
472 | | - " AND synt.defined_meaning_id=col.collection_mid " . |
473 | | - " AND dm.defined_meaning_id = synt.defined_meaning_id " . |
474 | | -// " AND synt.identical_meaning=1" . |
475 | | - " AND ( " . |
476 | | - " exp.language_id=$lng " . |
477 | | - " OR (" . |
478 | | - " exp.language_id=85 " . |
479 | | - " AND dm.defined_meaning_id NOT IN " . |
480 | | - " ( SELECT defined_meaning_id FROM {$dc}_syntrans synt_bis, {$dc}_expression exp_bis " . |
481 | | - " WHERE exp_bis.expression_id = synt_bis.expression_id AND exp_bis.language_id=$lng " . |
482 | | - " AND synt_bis.remove_transaction_id IS NULL AND exp_bis.remove_transaction_id IS NULL ) " . |
| 448 | + $sql = "SELECT collection_id, spelling " . |
| 449 | + " FROM {$dc}_expression exp, {$dc}_collection col, {$dc}_syntrans synt, {$dc}_defined_meaning dm " . |
| 450 | + " WHERE exp.expression_id=synt.expression_id " . |
| 451 | + " AND synt.defined_meaning_id=col.collection_mid " . |
| 452 | + " AND dm.defined_meaning_id = synt.defined_meaning_id " . |
| 453 | +// " AND synt.identical_meaning=1" . |
| 454 | + " AND ( " . |
| 455 | + " exp.language_id=$lng " . |
| 456 | + " OR (" . |
| 457 | + " exp.language_id=85 " . |
| 458 | + " AND dm.defined_meaning_id NOT IN " . |
| 459 | + " ( SELECT defined_meaning_id FROM {$dc}_syntrans synt_bis, {$dc}_expression exp_bis " . |
| 460 | + " WHERE exp_bis.expression_id = synt_bis.expression_id AND exp_bis.language_id=$lng " . |
| 461 | + " AND synt_bis.remove_transaction_id IS NULL AND exp_bis.remove_transaction_id IS NULL ) " . |
| 462 | + " ) " . |
483 | 463 | " ) " . |
484 | | - " ) " . |
485 | | - " AND " . getLatestTransactionRestriction( "synt" ) . |
486 | | - " AND " . getLatestTransactionRestriction( "exp" ) . |
487 | | - " AND " . getLatestTransactionRestriction( "col" ) . |
488 | | - " AND " . getLatestTransactionRestriction( "dm" ); |
| 464 | + " AND " . getLatestTransactionRestriction( "synt" ) . |
| 465 | + " AND " . getLatestTransactionRestriction( "exp" ) . |
| 466 | + " AND " . getLatestTransactionRestriction( "col" ) . |
| 467 | + " AND " . getLatestTransactionRestriction( "dm" ); |
489 | 468 | |
490 | | - return $sql; |
491 | | -} |
| 469 | + return $sql; |
| 470 | + } |
492 | 471 | |
493 | | -function getSQLForLevels( $language = "<ANY>" ) { |
494 | | - global $classAttributeLevels, $dataSet; |
495 | | - |
496 | | - $o = OmegaWikiAttributes::getInstance(); |
497 | | - // TO DO: Add support for multiple languages here |
498 | | - return |
499 | | - selectLatest( |
500 | | - array( $dataSet->bootstrappedDefinedMeanings->definedMeaningId, $dataSet->expression->spelling ), |
501 | | - array( $dataSet->definedMeaning, $dataSet->expression, $dataSet->bootstrappedDefinedMeanings ), |
502 | | - array( |
503 | | - 'name IN (' . implodeFixed( $classAttributeLevels ) . ')', |
504 | | - equals( $dataSet->definedMeaning->definedMeaningId, $dataSet->bootstrappedDefinedMeanings->definedMeaningId ), |
505 | | - equals( $dataSet->definedMeaning->expressionId, $dataSet->expression->expressionId ) |
506 | | - ) |
507 | | - ); |
508 | | -} |
| 472 | + private function getSQLForLevels( $language = "<ANY>" ) { |
| 473 | + global $classAttributeLevels, $dataSet; |
509 | 474 | |
510 | | -function getRelationTypeAsRecordSet( $queryResult ) { |
| 475 | + $o = OmegaWikiAttributes::getInstance(); |
| 476 | + // TO DO: Add support for multiple languages here |
| 477 | + return |
| 478 | + selectLatest( |
| 479 | + array( $dataSet->bootstrappedDefinedMeanings->definedMeaningId, $dataSet->expression->spelling ), |
| 480 | + array( $dataSet->definedMeaning, $dataSet->expression, $dataSet->bootstrappedDefinedMeanings ), |
| 481 | + array( |
| 482 | + 'name IN (' . implodeFixed( $classAttributeLevels ) . ')', |
| 483 | + equals( $dataSet->definedMeaning->definedMeaningId, $dataSet->bootstrappedDefinedMeanings->definedMeaningId ), |
| 484 | + equals( $dataSet->definedMeaning->expressionId, $dataSet->expression->expressionId ) |
| 485 | + ) |
| 486 | + ); |
| 487 | + } |
511 | 488 | |
512 | | - $o = OmegaWikiAttributes::getInstance(); |
| 489 | + private function getRelationTypeAsRecordSet( $queryResult ) { |
513 | 490 | |
514 | | - $dbr = wfGetDB( DB_SLAVE ); |
| 491 | + $o = OmegaWikiAttributes::getInstance(); |
| 492 | + |
| 493 | + $dbr = wfGetDB( DB_SLAVE ); |
515 | 494 | |
516 | | - $relationTypeAttribute = new Attribute( "relation-type", wfMsg( 'ow_RelationType' ), "short-text" ); |
517 | | - $collectionAttribute = new Attribute( "collection", wfMsg( 'ow_Collection' ), "short-text" ); |
| 495 | + $relationTypeAttribute = new Attribute( "relation-type", wfMsg( 'ow_RelationType' ), "short-text" ); |
| 496 | + $collectionAttribute = new Attribute( "collection", wfMsg( 'ow_Collection' ), "short-text" ); |
518 | 497 | |
519 | | - $recordSet = new ArrayRecordSet( new Structure( $o->id, $relationTypeAttribute, $collectionAttribute ), new Structure( $o->id ) ); |
| 498 | + $recordSet = new ArrayRecordSet( new Structure( $o->id, $relationTypeAttribute, $collectionAttribute ), new Structure( $o->id ) ); |
520 | 499 | |
521 | | - while ( $row = $dbr->fetchObject( $queryResult ) ) |
522 | | - $recordSet->addRecord( array( $row->member_mid, $row->spelling, definedMeaningExpression( $row->collection_mid ) ) ); |
| 500 | + while ( $row = $dbr->fetchObject( $queryResult ) ) |
| 501 | + $recordSet->addRecord( array( $row->member_mid, $row->spelling, definedMeaningExpression( $row->collection_mid ) ) ); |
523 | 502 | |
524 | | - $editor = createSuggestionsTableViewer( null ); |
525 | | - $editor->addEditor( createShortTextViewer( $relationTypeAttribute ) ); |
526 | | - $editor->addEditor( createShortTextViewer( $collectionAttribute ) ); |
527 | | - |
528 | | - return array( $recordSet, $editor ); |
529 | | -} |
| 503 | + $editor = createSuggestionsTableViewer( null ); |
| 504 | + $editor->addEditor( createShortTextViewer( $relationTypeAttribute ) ); |
| 505 | + $editor->addEditor( createShortTextViewer( $collectionAttribute ) ); |
530 | 506 | |
531 | | -/** |
532 | | - * Writes an html table from a sql table corresponding to the list of classes, as shown by |
533 | | - * http://www.omegawiki.org/index.php?title=Special:Suggest&query=class |
534 | | - * |
535 | | - * @param $queryResult the result of a SQL query to be made into an html table |
536 | | - */ |
537 | | -function getClassAsRecordSet( $queryResult ) { |
| 507 | + return array( $recordSet, $editor ); |
| 508 | + } |
538 | 509 | |
539 | | - $o = OmegaWikiAttributes::getInstance(); |
540 | | - |
541 | | - $dbr = wfGetDB( DB_SLAVE ); |
542 | | - // Setting the two column, with titles |
543 | | - $classAttribute = new Attribute( "class", wfMsg( 'ow_Class' ), "short-text" ); |
544 | | - $definitionAttribute = new Attribute( "definition", wfMsg( 'ow_Definition' ), "short-text" ); |
| 510 | + /** |
| 511 | + * Writes an html table from a sql table corresponding to the list of classes, as shown by |
| 512 | + * http://www.omegawiki.org/index.php?title=Special:Suggest&query=class |
| 513 | + * |
| 514 | + * @param $queryResult the result of a SQL query to be made into an html table |
| 515 | + */ |
| 516 | + function getClassAsRecordSet( $queryResult ) { |
545 | 517 | |
546 | | - $recordSet = new ArrayRecordSet( new Structure( $o->id, $classAttribute, $definitionAttribute ), new Structure( $o->id ) ); |
| 518 | + $o = OmegaWikiAttributes::getInstance(); |
547 | 519 | |
548 | | - while ( $row = $dbr->fetchObject( $queryResult ) ) { |
549 | | - $recordSet->addRecord( array( $row->member_mid, $row->spelling, getDefinedMeaningDefinition( $row->member_mid ) ) ); |
550 | | - } |
| 520 | + $dbr = wfGetDB( DB_SLAVE ); |
| 521 | + // Setting the two column, with titles |
| 522 | + $classAttribute = new Attribute( "class", wfMsg( 'ow_Class' ), "short-text" ); |
| 523 | + $definitionAttribute = new Attribute( "definition", wfMsg( 'ow_Definition' ), "short-text" ); |
551 | 524 | |
552 | | - $editor = createSuggestionsTableViewer( null ); |
553 | | - $editor->addEditor( createShortTextViewer( $classAttribute ) ); |
554 | | - $editor->addEditor( createShortTextViewer( $definitionAttribute ) ); |
| 525 | + $recordSet = new ArrayRecordSet( new Structure( $o->id, $classAttribute, $definitionAttribute ), new Structure( $o->id ) ); |
555 | 526 | |
556 | | - return array( $recordSet, $editor ); |
557 | | -} |
| 527 | + while ( $row = $dbr->fetchObject( $queryResult ) ) { |
| 528 | + $recordSet->addRecord( array( $row->member_mid, $row->spelling, getDefinedMeaningDefinition( $row->member_mid ) ) ); |
| 529 | + } |
558 | 530 | |
559 | | -function getDefinedMeaningAttributeAsRecordSet( $queryResult ) { |
560 | | - $o = OmegaWikiAttributes::getInstance(); |
561 | | - global $wgDefinedMeaningAttributes; |
| 531 | + $editor = createSuggestionsTableViewer( null ); |
| 532 | + $editor->addEditor( createShortTextViewer( $classAttribute ) ); |
| 533 | + $editor->addEditor( createShortTextViewer( $definitionAttribute ) ); |
562 | 534 | |
563 | | - $dbr = wfGetDB( DB_SLAVE ); |
| 535 | + return array( $recordSet, $editor ); |
| 536 | + } |
| 537 | + |
| 538 | + private function getDefinedMeaningAttributeAsRecordSet( $queryResult ) { |
| 539 | + global $wgDefinedMeaningAttributes; |
| 540 | + |
| 541 | + $o = OmegaWikiAttributes::getInstance(); |
| 542 | + |
| 543 | + $dbr = wfGetDB( DB_SLAVE ); |
564 | 544 | |
565 | | - $definedMeaningAttributeAttribute = new Attribute( $wgDefinedMeaningAttributes, wfMsgSc( "DefinedMeaningAttributes" ), "short-text" ); |
566 | | - $recordSet = new ArrayRecordSet( new Structure( $o->id, $definedMeaningAttributeAttribute ), new Structure( $o->id ) ); |
| 545 | + $definedMeaningAttributeAttribute = new Attribute( $wgDefinedMeaningAttributes, wfMsgSc( "DefinedMeaningAttributes" ), "short-text" ); |
| 546 | + $recordSet = new ArrayRecordSet( new Structure( $o->id, $definedMeaningAttributeAttribute ), new Structure( $o->id ) ); |
567 | 547 | |
568 | | - while ( $row = $dbr->fetchObject( $queryResult ) ) |
569 | | - $recordSet->addRecord( array( $row->attribute_mid, $row->spelling ) ); |
| 548 | + while ( $row = $dbr->fetchObject( $queryResult ) ) |
| 549 | + $recordSet->addRecord( array( $row->attribute_mid, $row->spelling ) ); |
570 | 550 | |
571 | | - $editor = createSuggestionsTableViewer( null ); |
572 | | - $editor->addEditor( createShortTextViewer( $definedMeaningAttributeAttribute ) ); |
| 551 | + $editor = createSuggestionsTableViewer( null ); |
| 552 | + $editor->addEditor( createShortTextViewer( $definedMeaningAttributeAttribute ) ); |
573 | 553 | |
574 | | - return array( $recordSet, $editor ); |
575 | | -} |
| 554 | + return array( $recordSet, $editor ); |
| 555 | + } |
576 | 556 | |
577 | | -function getTextAttributeAsRecordSet( $queryResult ) { |
| 557 | + private function getTextAttributeAsRecordSet( $queryResult ) { |
578 | 558 | |
579 | | - $o = OmegaWikiAttributes::getInstance(); |
580 | | - |
581 | | - $dbr = wfGetDB( DB_SLAVE ); |
582 | | - |
583 | | - $textAttributeAttribute = new Attribute( "text-attribute", wfMsg( 'ow_TextAttributeHeader' ), "short-text" ); |
584 | | - $recordSet = new ArrayRecordSet( new Structure( $o->id, $textAttributeAttribute ), new Structure( $o->id ) ); |
585 | | - |
586 | | - while ( $row = $dbr->fetchObject( $queryResult ) ) |
587 | | - $recordSet->addRecord( array( $row->attribute_mid, $row->spelling ) ); |
| 559 | + $o = OmegaWikiAttributes::getInstance(); |
588 | 560 | |
589 | | - $editor = createSuggestionsTableViewer( null ); |
590 | | - $editor->addEditor( createShortTextViewer( $textAttributeAttribute ) ); |
| 561 | + $dbr = wfGetDB( DB_SLAVE ); |
591 | 562 | |
592 | | - return array( $recordSet, $editor ); |
593 | | -} |
| 563 | + $textAttributeAttribute = new Attribute( "text-attribute", wfMsg( 'ow_TextAttributeHeader' ), "short-text" ); |
| 564 | + $recordSet = new ArrayRecordSet( new Structure( $o->id, $textAttributeAttribute ), new Structure( $o->id ) ); |
594 | 565 | |
595 | | -function getLinkAttributeAsRecordSet( $queryResult ) { |
596 | | - $o = OmegaWikiAttributes::getInstance(); |
597 | | - global $wgLinkAttribute; |
| 566 | + while ( $row = $dbr->fetchObject( $queryResult ) ) |
| 567 | + $recordSet->addRecord( array( $row->attribute_mid, $row->spelling ) ); |
598 | 568 | |
599 | | - $dbr = wfGetDB( DB_SLAVE ); |
600 | | - |
601 | | - $linkAttributeAttribute = new Attribute( $wgLinkAttribute, wfMsg( 'ow_LinkAttributeHeader' ), "short-text" ); |
602 | | - $recordSet = new ArrayRecordSet( new Structure( $o->id, $linkAttributeAttribute ), new Structure( $o->id ) ); |
603 | | - |
604 | | - while ( $row = $dbr->fetchObject( $queryResult ) ) |
605 | | - $recordSet->addRecord( array( $row->attribute_mid, $row->spelling ) ); |
| 569 | + $editor = createSuggestionsTableViewer( null ); |
| 570 | + $editor->addEditor( createShortTextViewer( $textAttributeAttribute ) ); |
606 | 571 | |
607 | | - $editor = createSuggestionsTableViewer( null ); |
608 | | - $editor->addEditor( createShortTextViewer( $linkAttributeAttribute ) ); |
| 572 | + return array( $recordSet, $editor ); |
| 573 | + } |
609 | 574 | |
610 | | - return array( $recordSet, $editor ); |
611 | | -} |
| 575 | + private function getLinkAttributeAsRecordSet( $queryResult ) { |
| 576 | + global $wgLinkAttribute; |
612 | 577 | |
613 | | -function getTranslatedTextAttributeAsRecordSet( $queryResult ) { |
| 578 | + $o = OmegaWikiAttributes::getInstance(); |
614 | 579 | |
615 | | - $o = OmegaWikiAttributes::getInstance(); |
616 | | - |
617 | | - $dbr = wfGetDB( DB_SLAVE ); |
618 | | - $translatedTextAttributeAttribute = new Attribute( "translated-text-attribute", "Translated text attribute", "short-text" ); |
619 | | - |
620 | | - $recordSet = new ArrayRecordSet( new Structure( $o->id, $translatedTextAttributeAttribute ), new Structure( $o->id ) ); |
621 | | - |
622 | | - while ( $row = $dbr->fetchObject( $queryResult ) ) |
623 | | - $recordSet->addRecord( array( $row->attribute_mid, $row->spelling ) ); |
| 580 | + $dbr = wfGetDB( DB_SLAVE ); |
624 | 581 | |
625 | | - $editor = createSuggestionsTableViewer( null ); |
626 | | - $editor->addEditor( createShortTextViewer( $translatedTextAttributeAttribute ) ); |
| 582 | + $linkAttributeAttribute = new Attribute( $wgLinkAttribute, wfMsg( 'ow_LinkAttributeHeader' ), "short-text" ); |
| 583 | + $recordSet = new ArrayRecordSet( new Structure( $o->id, $linkAttributeAttribute ), new Structure( $o->id ) ); |
627 | 584 | |
628 | | - return array( $recordSet, $editor ); |
629 | | -} |
| 585 | + while ( $row = $dbr->fetchObject( $queryResult ) ) |
| 586 | + $recordSet->addRecord( array( $row->attribute_mid, $row->spelling ) ); |
630 | 587 | |
631 | | -function getOptionAttributeAsRecordSet( $queryResult ) { |
632 | | - $o = OmegaWikiAttributes::getInstance(); |
633 | | - global $wgOptionAttribute; |
| 588 | + $editor = createSuggestionsTableViewer( null ); |
| 589 | + $editor->addEditor( createShortTextViewer( $linkAttributeAttribute ) ); |
634 | 590 | |
635 | | - $dbr = wfGetDB( DB_SLAVE ); |
636 | | - |
637 | | - $optionAttributeAttribute = new Attribute( $wgOptionAttribute, wfMsg( 'ow_OptionAttributeHeader' ), "short-text" ); |
638 | | - $recordSet = new ArrayRecordSet( new Structure( $o->id, $optionAttributeAttribute ), new Structure( $o->id ) ); |
639 | | - |
640 | | - while ( $row = $dbr->fetchObject( $queryResult ) ) |
641 | | - $recordSet->addRecord( array( $row->attribute_mid, $row->spelling ) ); |
| 591 | + return array( $recordSet, $editor ); |
| 592 | + } |
642 | 593 | |
643 | | - $editor = createSuggestionsTableViewer( null ); |
644 | | - $editor->addEditor( createShortTextViewer( $optionAttributeAttribute ) ); |
| 594 | + private function getTranslatedTextAttributeAsRecordSet( $queryResult ) { |
645 | 595 | |
646 | | - return array( $recordSet, $editor ); |
647 | | -} |
| 596 | + $o = OmegaWikiAttributes::getInstance(); |
648 | 597 | |
649 | | -function getDefinedMeaningAsRecordSet( $queryResult ) { |
| 598 | + $dbr = wfGetDB( DB_SLAVE ); |
| 599 | + $translatedTextAttributeAttribute = new Attribute( "translated-text-attribute", "Translated text attribute", "short-text" ); |
650 | 600 | |
651 | | - $o = OmegaWikiAttributes::getInstance(); |
652 | | - global $wgDefinedMeaning ; |
| 601 | + $recordSet = new ArrayRecordSet( new Structure( $o->id, $translatedTextAttributeAttribute ), new Structure( $o->id ) ); |
653 | 602 | |
654 | | - $dbr = wfGetDB( DB_SLAVE ); |
655 | | - $spellingAttribute = new Attribute( "spelling", wfMsg( 'ow_Spelling' ), "short-text" ); |
656 | | - $languageAttribute = new Attribute( "language", wfMsg( 'ow_Language' ), "language" ); |
657 | | - |
658 | | - $expressionStructure = new Structure( $wgDefinedMeaning, $spellingAttribute, $languageAttribute ); |
659 | | - $definedMeaningAttribute = new Attribute( null, wfMsg( 'ow_DefinedMeaning' ), $expressionStructure ); |
660 | | - $definitionAttribute = new Attribute( "definition", wfMsg( 'ow_Definition' ), "definition" ); |
661 | | - |
662 | | - $recordSet = new ArrayRecordSet( new Structure( $o->id, $definedMeaningAttribute, $definitionAttribute ), new Structure( $o->id ) ); |
663 | | - |
664 | | - while ( $row = $dbr->fetchObject( $queryResult ) ) { |
665 | | - $definedMeaningRecord = new ArrayRecord( $expressionStructure ); |
666 | | - $definedMeaningRecord->setAttributeValue( $spellingAttribute, $row->spelling ); |
667 | | - $definedMeaningRecord->setAttributeValue( $languageAttribute, $row->language_id ); |
668 | | - |
669 | | - $recordSet->addRecord( array( $row->defined_meaning_id, $definedMeaningRecord, getDefinedMeaningDefinition( $row->defined_meaning_id ) ) ); |
| 603 | + while ( $row = $dbr->fetchObject( $queryResult ) ) |
| 604 | + $recordSet->addRecord( array( $row->attribute_mid, $row->spelling ) ); |
| 605 | + |
| 606 | + $editor = createSuggestionsTableViewer( null ); |
| 607 | + $editor->addEditor( createShortTextViewer( $translatedTextAttributeAttribute ) ); |
| 608 | + |
| 609 | + return array( $recordSet, $editor ); |
670 | 610 | } |
671 | 611 | |
672 | | - $expressionEditor = new RecordTableCellEditor( $definedMeaningAttribute ); |
673 | | - $expressionEditor->addEditor( createShortTextViewer( $spellingAttribute ) ); |
674 | | - $expressionEditor->addEditor( createLanguageViewer( $languageAttribute ) ); |
| 612 | + private function getOptionAttributeAsRecordSet( $queryResult ) { |
| 613 | + global $wgOptionAttribute; |
675 | 614 | |
676 | | - $editor = createSuggestionsTableViewer( null ); |
677 | | - $editor->addEditor( $expressionEditor ); |
678 | | - $editor->addEditor( new TextEditor( $definitionAttribute, new SimplePermissionController( false ), false, true, 75 ) ); |
| 615 | + $o = OmegaWikiAttributes::getInstance(); |
679 | 616 | |
680 | | - return array( $recordSet, $editor ); |
681 | | -} |
| 617 | + $dbr = wfGetDB( DB_SLAVE ); |
682 | 618 | |
683 | | -function getClassAttributeLevelAsRecordSet( $queryResult ) { |
| 619 | + $optionAttributeAttribute = new Attribute( $wgOptionAttribute, wfMsg( 'ow_OptionAttributeHeader' ), "short-text" ); |
| 620 | + $recordSet = new ArrayRecordSet( new Structure( $o->id, $optionAttributeAttribute ), new Structure( $o->id ) ); |
684 | 621 | |
685 | | - $o = OmegaWikiAttributes::getInstance(); |
686 | | - |
687 | | - $dbr = wfGetDB( DB_SLAVE ); |
| 622 | + while ( $row = $dbr->fetchObject( $queryResult ) ) |
| 623 | + $recordSet->addRecord( array( $row->attribute_mid, $row->spelling ) ); |
688 | 624 | |
689 | | - $classAttributeLevelAttribute = new Attribute( "class-attribute-level", wfMsg( 'ow_ClassAttributeLevel' ), "short-text" ); |
690 | | - $recordSet = new ArrayRecordSet( new Structure( $o->id, $classAttributeLevelAttribute ), new Structure( $o->id ) ); |
| 625 | + $editor = createSuggestionsTableViewer( null ); |
| 626 | + $editor->addEditor( createShortTextViewer( $optionAttributeAttribute ) ); |
691 | 627 | |
692 | | - while ( $row = $dbr->fetchObject( $queryResult ) ) |
693 | | - $recordSet->addRecord( array( $row->defined_meaning_id, $row->spelling ) ); |
| 628 | + return array( $recordSet, $editor ); |
| 629 | + } |
694 | 630 | |
695 | | - $editor = createSuggestionsTableViewer( null ); |
696 | | - $editor->addEditor( createShortTextViewer( $classAttributeLevelAttribute ) ); |
697 | | - |
698 | | - return array( $recordSet, $editor ); |
699 | | -} |
| 631 | + private function getDefinedMeaningAsRecordSet( $queryResult ) { |
| 632 | + global $wgDefinedMeaning ; |
700 | 633 | |
701 | | -function getCollectionAsRecordSet( $queryResult ) { |
| 634 | + $o = OmegaWikiAttributes::getInstance(); |
702 | 635 | |
703 | | - $o = OmegaWikiAttributes::getInstance(); |
| 636 | + $dbr = wfGetDB( DB_SLAVE ); |
| 637 | + $spellingAttribute = new Attribute( "spelling", wfMsg( 'ow_Spelling' ), "short-text" ); |
| 638 | + $languageAttribute = new Attribute( "language", wfMsg( 'ow_Language' ), "language" ); |
704 | 639 | |
705 | | - $dbr = wfGetDB( DB_SLAVE ); |
706 | | - $collectionAttribute = new Attribute( "collection", wfMsg( 'ow_Collection' ), "short-text" ); |
707 | | - |
708 | | - $recordSet = new ArrayRecordSet( new Structure( $o->id, $collectionAttribute ), new Structure( $o->id ) ); |
709 | | - |
710 | | - while ( $row = $dbr->fetchObject( $queryResult ) ) |
711 | | - $recordSet->addRecord( array( $row->collection_id, $row->spelling ) ); |
| 640 | + $expressionStructure = new Structure( $wgDefinedMeaning, $spellingAttribute, $languageAttribute ); |
| 641 | + $definedMeaningAttribute = new Attribute( null, wfMsg( 'ow_DefinedMeaning' ), $expressionStructure ); |
| 642 | + $definitionAttribute = new Attribute( "definition", wfMsg( 'ow_Definition' ), "definition" ); |
712 | 643 | |
713 | | - $editor = createSuggestionsTableViewer( null ); |
714 | | - $editor->addEditor( createShortTextViewer( $collectionAttribute ) ); |
| 644 | + $recordSet = new ArrayRecordSet( new Structure( $o->id, $definedMeaningAttribute, $definitionAttribute ), new Structure( $o->id ) ); |
715 | 645 | |
716 | | - return array( $recordSet, $editor ); |
717 | | -} |
| 646 | + while ( $row = $dbr->fetchObject( $queryResult ) ) { |
| 647 | + $definedMeaningRecord = new ArrayRecord( $expressionStructure ); |
| 648 | + $definedMeaningRecord->setAttributeValue( $spellingAttribute, $row->spelling ); |
| 649 | + $definedMeaningRecord->setAttributeValue( $languageAttribute, $row->language_id ); |
718 | 650 | |
719 | | -function getLanguageAsRecordSet( $queryResult ) { |
| 651 | + $recordSet->addRecord( array( $row->defined_meaning_id, $definedMeaningRecord, getDefinedMeaningDefinition( $row->defined_meaning_id ) ) ); |
| 652 | + } |
720 | 653 | |
721 | | - $o = OmegaWikiAttributes::getInstance(); |
| 654 | + $expressionEditor = new RecordTableCellEditor( $definedMeaningAttribute ); |
| 655 | + $expressionEditor->addEditor( createShortTextViewer( $spellingAttribute ) ); |
| 656 | + $expressionEditor->addEditor( createLanguageViewer( $languageAttribute ) ); |
722 | 657 | |
723 | | - $dbr = wfGetDB( DB_SLAVE ); |
724 | | - $languageAttribute = new Attribute( "language", wfMsg( 'ow_Language' ), "short-text" ); |
725 | | - |
726 | | - $recordSet = new ArrayRecordSet( new Structure( $o->id, $languageAttribute ), new Structure( $o->id ) ); |
727 | | - |
728 | | - while ( $row = $dbr->fetchObject( $queryResult ) ) { |
729 | | - $recordSet->addRecord( array( $row->row_id, $row->language_name ) ); |
| 658 | + $editor = createSuggestionsTableViewer( null ); |
| 659 | + $editor->addEditor( $expressionEditor ); |
| 660 | + $editor->addEditor( new TextEditor( $definitionAttribute, new SimplePermissionController( false ), false, true, 75 ) ); |
| 661 | + |
| 662 | + return array( $recordSet, $editor ); |
730 | 663 | } |
731 | | - $editor = createSuggestionsTableViewer( null ); |
732 | | - $editor->addEditor( createShortTextViewer( $languageAttribute ) ); |
733 | 664 | |
734 | | - return array( $recordSet, $editor ); |
735 | | -} |
| 665 | + private function getClassAttributeLevelAsRecordSet( $queryResult ) { |
736 | 666 | |
737 | | -function getTransactionAsRecordSet( $queryResult ) { |
| 667 | + $o = OmegaWikiAttributes::getInstance(); |
738 | 668 | |
739 | | - $o = OmegaWikiAttributes::getInstance(); |
740 | | - |
741 | | - $dbr = wfGetDB( DB_SLAVE ); |
742 | | - |
743 | | - $userAttribute = new Attribute( "user", wfMsg( 'ow_User' ), "short-text" ); |
744 | | - $timestampAttribute = new Attribute( "timestamp", wfMsg( 'ow_Time' ), "timestamp" ); |
745 | | - $summaryAttribute = new Attribute( "summary", wfMsg( 'ow_transaction_summary' ), "short-text" ); |
746 | | - |
747 | | - $recordSet = new ArrayRecordSet( new Structure( $o->id, $userAttribute, $timestampAttribute, $summaryAttribute ), new Structure( $o->id ) ); |
748 | | - |
749 | | - while ( $row = $dbr->fetchObject( $queryResult ) ) |
750 | | - $recordSet->addRecord( array( $row->transaction_id, getUserLabel( $row->user_id, $row->user_ip ), $row->time, $row->comment ) ); |
751 | | - |
752 | | - $editor = createSuggestionsTableViewer( null ); |
753 | | - $editor->addEditor( createShortTextViewer( $timestampAttribute ) ); |
754 | | - $editor->addEditor( createShortTextViewer( $o->id ) ); |
755 | | - $editor->addEditor( createShortTextViewer( $userAttribute ) ); |
756 | | - $editor->addEditor( createShortTextViewer( $summaryAttribute ) ); |
| 669 | + $dbr = wfGetDB( DB_SLAVE ); |
757 | 670 | |
758 | | - return array( $recordSet, $editor ); |
759 | | -} |
| 671 | + $classAttributeLevelAttribute = new Attribute( "class-attribute-level", wfMsg( 'ow_ClassAttributeLevel' ), "short-text" ); |
| 672 | + $recordSet = new ArrayRecordSet( new Structure( $o->id, $classAttributeLevelAttribute ), new Structure( $o->id ) ); |
760 | 673 | |
| 674 | + while ( $row = $dbr->fetchObject( $queryResult ) ) |
| 675 | + $recordSet->addRecord( array( $row->defined_meaning_id, $row->spelling ) ); |
761 | 676 | |
| 677 | + $editor = createSuggestionsTableViewer( null ); |
| 678 | + $editor->addEditor( createShortTextViewer( $classAttributeLevelAttribute ) ); |
| 679 | + |
| 680 | + return array( $recordSet, $editor ); |
| 681 | + } |
| 682 | + |
| 683 | + private function getCollectionAsRecordSet( $queryResult ) { |
| 684 | + |
| 685 | + $o = OmegaWikiAttributes::getInstance(); |
| 686 | + |
| 687 | + $dbr = wfGetDB( DB_SLAVE ); |
| 688 | + $collectionAttribute = new Attribute( "collection", wfMsg( 'ow_Collection' ), "short-text" ); |
| 689 | + |
| 690 | + $recordSet = new ArrayRecordSet( new Structure( $o->id, $collectionAttribute ), new Structure( $o->id ) ); |
| 691 | + |
| 692 | + while ( $row = $dbr->fetchObject( $queryResult ) ) |
| 693 | + $recordSet->addRecord( array( $row->collection_id, $row->spelling ) ); |
| 694 | + |
| 695 | + $editor = createSuggestionsTableViewer( null ); |
| 696 | + $editor->addEditor( createShortTextViewer( $collectionAttribute ) ); |
| 697 | + |
| 698 | + return array( $recordSet, $editor ); |
| 699 | + } |
| 700 | + |
| 701 | + private function getLanguageAsRecordSet( $queryResult ) { |
| 702 | + |
| 703 | + $o = OmegaWikiAttributes::getInstance(); |
| 704 | + |
| 705 | + $dbr = wfGetDB( DB_SLAVE ); |
| 706 | + $languageAttribute = new Attribute( "language", wfMsg( 'ow_Language' ), "short-text" ); |
| 707 | + |
| 708 | + $recordSet = new ArrayRecordSet( new Structure( $o->id, $languageAttribute ), new Structure( $o->id ) ); |
| 709 | + |
| 710 | + while ( $row = $dbr->fetchObject( $queryResult ) ) { |
| 711 | + $recordSet->addRecord( array( $row->row_id, $row->language_name ) ); |
| 712 | + } |
| 713 | + $editor = createSuggestionsTableViewer( null ); |
| 714 | + $editor->addEditor( createShortTextViewer( $languageAttribute ) ); |
| 715 | + |
| 716 | + return array( $recordSet, $editor ); |
| 717 | + } |
| 718 | + |
| 719 | + private function getTransactionAsRecordSet( $queryResult ) { |
| 720 | + |
| 721 | + $o = OmegaWikiAttributes::getInstance(); |
| 722 | + |
| 723 | + $dbr = wfGetDB( DB_SLAVE ); |
| 724 | + |
| 725 | + $userAttribute = new Attribute( "user", wfMsg( 'ow_User' ), "short-text" ); |
| 726 | + $timestampAttribute = new Attribute( "timestamp", wfMsg( 'ow_Time' ), "timestamp" ); |
| 727 | + $summaryAttribute = new Attribute( "summary", wfMsg( 'ow_transaction_summary' ), "short-text" ); |
| 728 | + |
| 729 | + $recordSet = new ArrayRecordSet( new Structure( $o->id, $userAttribute, $timestampAttribute, $summaryAttribute ), new Structure( $o->id ) ); |
| 730 | + |
| 731 | + while ( $row = $dbr->fetchObject( $queryResult ) ) |
| 732 | + $recordSet->addRecord( array( $row->transaction_id, getUserLabel( $row->user_id, $row->user_ip ), $row->time, $row->comment ) ); |
| 733 | + |
| 734 | + $editor = createSuggestionsTableViewer( null ); |
| 735 | + $editor->addEditor( createShortTextViewer( $timestampAttribute ) ); |
| 736 | + $editor->addEditor( createShortTextViewer( $o->id ) ); |
| 737 | + $editor->addEditor( createShortTextViewer( $userAttribute ) ); |
| 738 | + $editor->addEditor( createShortTextViewer( $summaryAttribute ) ); |
| 739 | + |
| 740 | + return array( $recordSet, $editor ); |
| 741 | + } |
| 742 | +} |
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialTransaction.php |
— | — | @@ -2,96 +2,89 @@ |
3 | 3 | |
4 | 4 | if ( !defined( 'MEDIAWIKI' ) ) die(); |
5 | 5 | |
6 | | -$wgExtensionFunctions[] = 'wfSpecialTransaction'; |
7 | 6 | require_once( "Wikidata.php" ); |
8 | 7 | require_once( "Utilities.php" ); |
9 | 8 | |
| 9 | +class SpecialTransaction extends SpecialPage { |
| 10 | + function SpecialTransaction() { |
| 11 | + parent::__construct( 'Transaction' ); |
| 12 | + } |
10 | 13 | |
11 | | -function wfSpecialTransaction() { |
12 | | - class SpecialTransaction extends SpecialPage { |
13 | | - function SpecialTransaction() { |
14 | | - parent::__construct( 'Transaction' ); |
15 | | - } |
16 | | - |
17 | | - function execute( $parameter ) { |
18 | | - global |
19 | | - $wgOut; |
20 | | - |
21 | | - require_once( "WikiDataTables.php" ); |
22 | | - require_once( "OmegaWikiAttributes.php" ); |
23 | | - require_once( "OmegaWikiRecordSets.php" ); |
24 | | - require_once( "OmegaWikiEditors.php" ); |
25 | | - require_once( "RecordSetQueries.php" ); |
26 | | - require_once( "Transaction.php" ); |
27 | | - require_once( "Editor.php" ); |
28 | | - require_once( "Controller.php" ); |
29 | | - require_once( "type.php" ); |
30 | | - require_once( "ViewInformation.php" ); |
31 | | - |
32 | | - initializeOmegaWikiAttributes( new ViewInformation() ); |
33 | | - initializeAttributes(); |
34 | | - |
35 | | - @$fromTransactionId = (int) $_GET['from-transaction']; # FIXME - check parameter |
36 | | - @$transactionCount = (int) $_GET['transaction-count']; # FIXME - check parameter |
37 | | - @$userName = "" . $_GET['user-name']; # FIXME - check parameter |
38 | | - @$showRollBackOptions = isset( $_GET['show-roll-back-options'] ); # FIXME - check parameter |
| 14 | + function execute( $parameter ) { |
| 15 | + global $wgOut; |
39 | 16 | |
40 | | - if ( isset( $_POST['roll-back'] ) ) { |
41 | | - $fromTransactionId = (int) $_POST['from-transaction']; |
42 | | - $transactionCount = (int) $_POST['transaction-count']; |
43 | | - $userName = "" . $_POST['user-name']; |
44 | | - |
45 | | - if ( $fromTransactionId != 0 ) { |
46 | | - $recordSet = getTransactionRecordSet( $fromTransactionId, $transactionCount, $userName ); |
47 | | - rollBackTransactions( $recordSet ); |
48 | | - $fromTransactionId = 0; |
49 | | - $userName = ""; |
50 | | - } |
51 | | - } |
| 17 | + require_once( "WikiDataTables.php" ); |
| 18 | + require_once( "OmegaWikiAttributes.php" ); |
| 19 | + require_once( "OmegaWikiRecordSets.php" ); |
| 20 | + require_once( "OmegaWikiEditors.php" ); |
| 21 | + require_once( "RecordSetQueries.php" ); |
| 22 | + require_once( "Transaction.php" ); |
| 23 | + require_once( "Editor.php" ); |
| 24 | + require_once( "Controller.php" ); |
| 25 | + require_once( "type.php" ); |
| 26 | + require_once( "ViewInformation.php" ); |
52 | 27 | |
53 | | - if ( $fromTransactionId == 0 ) |
54 | | - $fromTransactionId = getLatestTransactionId(); |
55 | | - |
56 | | - if ( $transactionCount == 0 ) |
57 | | - $transactionCount = 10; |
58 | | - else |
59 | | - $transactionCount = min( $transactionCount, 20 ); |
60 | | - |
61 | | - $wgOut->setPageTitle( wfMsg( 'recentchanges' ) ); |
62 | | - $wgOut->addHTML( getFilterOptionsPanel( $fromTransactionId, $transactionCount, $userName, $showRollBackOptions ) ); |
| 28 | + initializeOmegaWikiAttributes( new ViewInformation() ); |
| 29 | + initializeAttributes(); |
63 | 30 | |
64 | | - if ( $showRollBackOptions ) |
65 | | - $wgOut->addHTML( |
66 | | - '<form method="post" action="">' . |
67 | | - '<input type="hidden" name="from-transaction" value="' . $fromTransactionId . '"/>' . |
68 | | - '<input type="hidden" name="transaction-count" value="' . $transactionCount . '"/>' . |
69 | | - '<input type="hidden" name="user-name" value="' . $userName . '"/>' |
70 | | - ); |
| 31 | + @$fromTransactionId = (int) $_GET['from-transaction']; # FIXME - check parameter |
| 32 | + @$transactionCount = (int) $_GET['transaction-count']; # FIXME - check parameter |
| 33 | + @$userName = "" . $_GET['user-name']; # FIXME - check parameter |
| 34 | + @$showRollBackOptions = isset( $_GET['show-roll-back-options'] ); # FIXME - check parameter |
71 | 35 | |
72 | | - $recordSet = getTransactionRecordSet( $fromTransactionId, $transactionCount, $userName ); |
73 | | - |
74 | | - $wgOut->addHTML( getTransactionOverview( $recordSet, $showRollBackOptions ) ); |
75 | | - |
76 | | - if ( $showRollBackOptions ) |
77 | | - $wgOut->addHTML( |
78 | | - '<div class="option-panel">' . |
79 | | - '<table cellpadding="0" cellspacing="0">' . |
80 | | - '<tr>' . |
81 | | - '<th>' . wfMsg( "summary" ) . ': </th>' . |
82 | | - '<td class="option-field">' . getTextBox( "summary" ) . '</td>' . |
83 | | - '</tr>' . |
84 | | - '<tr><th/><td>' . getSubmitButton( "roll-back", wfMsg( 'ow_transaction_rollback_button' ) ) . '</td></tr>' . |
85 | | - '</table>' . |
86 | | - '</div>' . |
87 | | - '</form>' |
88 | | - ); |
89 | | - |
90 | | - $wgOut->addHTML( DefaultEditor::getExpansionCss() ); |
91 | | - $wgOut->addHTML( "<script language='javascript'>/* <![CDATA[ */\nexpandEditors();\n/* ]]> */</script>" ); |
| 36 | + if ( isset( $_POST['roll-back'] ) ) { |
| 37 | + $fromTransactionId = (int) $_POST['from-transaction']; |
| 38 | + $transactionCount = (int) $_POST['transaction-count']; |
| 39 | + $userName = "" . $_POST['user-name']; |
| 40 | + |
| 41 | + if ( $fromTransactionId != 0 ) { |
| 42 | + $recordSet = getTransactionRecordSet( $fromTransactionId, $transactionCount, $userName ); |
| 43 | + rollBackTransactions( $recordSet ); |
| 44 | + $fromTransactionId = 0; |
| 45 | + $userName = ""; |
| 46 | + } |
92 | 47 | } |
| 48 | + |
| 49 | + if ( $fromTransactionId == 0 ) |
| 50 | + $fromTransactionId = getLatestTransactionId(); |
| 51 | + |
| 52 | + if ( $transactionCount == 0 ) |
| 53 | + $transactionCount = 10; |
| 54 | + else |
| 55 | + $transactionCount = min( $transactionCount, 20 ); |
| 56 | + |
| 57 | + $wgOut->setPageTitle( wfMsg( 'recentchanges' ) ); |
| 58 | + $wgOut->addHTML( getFilterOptionsPanel( $fromTransactionId, $transactionCount, $userName, $showRollBackOptions ) ); |
| 59 | + |
| 60 | + if ( $showRollBackOptions ) |
| 61 | + $wgOut->addHTML( |
| 62 | + '<form method="post" action="">' . |
| 63 | + '<input type="hidden" name="from-transaction" value="' . $fromTransactionId . '"/>' . |
| 64 | + '<input type="hidden" name="transaction-count" value="' . $transactionCount . '"/>' . |
| 65 | + '<input type="hidden" name="user-name" value="' . $userName . '"/>' |
| 66 | + ); |
| 67 | + |
| 68 | + $recordSet = getTransactionRecordSet( $fromTransactionId, $transactionCount, $userName ); |
| 69 | + |
| 70 | + $wgOut->addHTML( getTransactionOverview( $recordSet, $showRollBackOptions ) ); |
| 71 | + |
| 72 | + if ( $showRollBackOptions ) |
| 73 | + $wgOut->addHTML( |
| 74 | + '<div class="option-panel">' . |
| 75 | + '<table cellpadding="0" cellspacing="0">' . |
| 76 | + '<tr>' . |
| 77 | + '<th>' . wfMsg( "summary" ) . ': </th>' . |
| 78 | + '<td class="option-field">' . getTextBox( "summary" ) . '</td>' . |
| 79 | + '</tr>' . |
| 80 | + '<tr><th/><td>' . getSubmitButton( "roll-back", wfMsg( 'ow_transaction_rollback_button' ) ) . '</td></tr>' . |
| 81 | + '</table>' . |
| 82 | + '</div>' . |
| 83 | + '</form>' |
| 84 | + ); |
| 85 | + |
| 86 | + $wgOut->addHTML( DefaultEditor::getExpansionCss() ); |
| 87 | + $wgOut->addHTML( "<script language='javascript'>/* <![CDATA[ */\nexpandEditors();\n/* ]]> */</script>" ); |
93 | 88 | } |
94 | | - |
95 | | - SpecialPage::addPage( new SpecialTransaction() ); |
96 | 89 | } |
97 | 90 | |
98 | 91 | function getFilterOptionsPanel( $fromTransactionId, $transactionCount, $userName, $showRollBackOptions ) { |
Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php |
— | — | @@ -1,7 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | require_once( 'Transaction.php' ); |
5 | | -require_once( 'Wikidata.php' ); |
6 | 5 | |
7 | 6 | class Expression { |
8 | 7 | public $id; |
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialOWStatistics.php |
— | — | @@ -1,260 +1,254 @@ |
2 | 2 | <?php |
3 | | - if ( !defined( 'MEDIAWIKI' ) ) die(); |
| 3 | +if ( !defined( 'MEDIAWIKI' ) ) die(); |
4 | 4 | |
5 | | - $wgExtensionFunctions[] = 'wfSpecialOWStatistics'; |
| 5 | +require_once( "Wikidata.php" ); |
| 6 | +require_once( 'languages.php' ); |
6 | 7 | |
7 | | - require_once( "Wikidata.php" ); |
8 | | - require_once( 'languages.php' ); |
| 8 | +class SpecialOWStatistics extends SpecialPage { |
| 9 | + function __construct() { |
| 10 | + parent::__construct( 'ow_statistics' ); |
| 11 | + } |
9 | 12 | |
10 | | - function wfSpecialOWStatistics() { |
11 | | - class SpecialOWStatistics extends SpecialPage { |
12 | | - function SpecialOWStatistics() { |
13 | | - parent::__construct( 'ow_statistics' ); |
14 | | - } |
| 13 | + function execute( $par ) { |
| 14 | + global $wgOut, $wgRequest; |
15 | 15 | |
16 | | - function execute( $par ) { |
17 | | - global $wgOut, $wgRequest; |
| 16 | + $wgOut->setPageTitle( wfMsg( 'ow_statistics' ) ); |
18 | 17 | |
19 | | - $wgOut->setPageTitle( wfMsg( 'ow_statistics' ) ); |
| 18 | + $showstat = array_key_exists( 'showstat', $_GET ) ? $_GET['showstat']:''; |
20 | 19 | |
21 | | - $showstat = array_key_exists( 'showstat', $_GET ) ? $_GET['showstat']:''; |
| 20 | + $headerText = '<big><div style="text-align:center; background-color:#DDFFDD;">' |
| 21 | + . $this->linkHeader ( wfMsg('ow_DefinedMeaning'), "dm", $showstat ) . " — " |
| 22 | + . $this->linkHeader ( wfMsg('ow_Definition'), "def", $showstat ) . " — " |
| 23 | + . $this->linkHeader ( wfMsg('ow_Expression'), "exp", $showstat ) . " — " |
| 24 | + . $this->linkHeader ( "Syntrans", "syntrans", $showstat ) |
| 25 | + . "</big></div><br /><br />" ; |
22 | 26 | |
23 | | - $headerText = '<big><div style="text-align:center; background-color:#DDFFDD;">' |
24 | | - . $this->linkHeader ( wfMsg('ow_DefinedMeaning'), "dm", $showstat ) . " — " |
25 | | - . $this->linkHeader ( wfMsg('ow_Definition'), "def", $showstat ) . " — " |
26 | | - . $this->linkHeader ( wfMsg('ow_Expression'), "exp", $showstat ) . " — " |
27 | | - . $this->linkHeader ( "Syntrans", "syntrans", $showstat ) |
28 | | - . "</big></div><br /><br />" ; |
| 27 | + $wgOut->addHTML( $headerText ) ; |
29 | 28 | |
30 | | - $wgOut->addHTML( $headerText ) ; |
| 29 | + if ( $showstat == 'dm' ) |
| 30 | + $wgOut->addHTML( $this->getDefinedMeaningPerLanguage () ); |
| 31 | + else if ( $showstat == 'def' ) |
| 32 | + $wgOut->addHTML( $this->getDefinitionPerLanguage () ); |
| 33 | + else if ( $showstat == 'syntrans' ) |
| 34 | + $wgOut->addHTML( $this->getSyntransPerLanguage () ); |
| 35 | + else if ( $showstat == 'exp' ) |
| 36 | + $wgOut->addHTML ( $this->getExpressionPerLanguage () ) ; |
| 37 | + } |
31 | 38 | |
32 | | - if ( $showstat == 'dm' ) |
33 | | - $wgOut->addHTML( $this->getDefinedMeaningPerLanguage () ); |
34 | | - else if ( $showstat == 'def' ) |
35 | | - $wgOut->addHTML( $this->getDefinitionPerLanguage () ); |
36 | | - else if ( $showstat == 'syntrans' ) |
37 | | - $wgOut->addHTML( $this->getSyntransPerLanguage () ); |
38 | | - else if ( $showstat == 'exp' ) |
39 | | - $wgOut->addHTML ( $this->getExpressionPerLanguage () ) ; |
40 | | - } |
| 39 | + function linkHeader ( $text, $val , $showstat ) { |
| 40 | + global $wgArticlePath; |
| 41 | + if ( $showstat != $val ) { |
| 42 | + $url = str_replace( "$1", 'Special:Ow_statistics' , $wgArticlePath ); |
| 43 | + $url .= strpos($url , "?") ? "&showstat=$val":"?showstat=$val"; |
| 44 | + return "<a href=\"$url\">$text</a>" ; |
| 45 | + } else { |
| 46 | + return "<b>$text</b>" ; |
| 47 | + } |
| 48 | + } |
41 | 49 | |
42 | | - function linkHeader ( $text, $val , $showstat ) { |
43 | | - global $wgArticlePath; |
44 | | - if ( $showstat != $val ) { |
45 | | - $url = str_replace( "$1", 'Special:Ow_statistics' , $wgArticlePath ); |
46 | | - $url .= strpos($url , "?") ? "&showstat=$val":"?showstat=$val"; |
47 | | - return "<a href=\"$url\">$text</a>" ; |
48 | | - } else { |
49 | | - return "<b>$text</b>" ; |
50 | | - } |
51 | | - } |
| 50 | + function getNumberOfDM ( ) { |
| 51 | + $dc = wdGetDataSetContext(); |
| 52 | + $dbr = wfGetDB( DB_SLAVE ); |
52 | 53 | |
53 | | - function getNumberOfDM ( ) { |
54 | | - $dc = wdGetDataSetContext(); |
55 | | - $dbr = wfGetDB( DB_SLAVE ); |
| 54 | + $sql = "SELECT COUNT(DISTINCT defined_meaning_id) as number " ; |
| 55 | + $sql .= "FROM " . "{$dc}_syntrans" . " WHERE remove_transaction_id IS NULL" ; |
56 | 56 | |
57 | | - $sql = "SELECT COUNT(DISTINCT defined_meaning_id) as number " ; |
58 | | - $sql .= "FROM " . "{$dc}_syntrans" . " WHERE remove_transaction_id IS NULL" ; |
| 57 | + $queryResult = $dbr->query( $sql ); |
| 58 | + $row = $dbr->fetchObject( $queryResult ) ; |
| 59 | + $nbdm = $row->number ; |
59 | 60 | |
60 | | - $queryResult = $dbr->query( $sql ); |
61 | | - $row = $dbr->fetchObject( $queryResult ) ; |
62 | | - $nbdm = $row->number ; |
| 61 | + return "$nbdm"; |
| 62 | + } |
63 | 63 | |
64 | | - return "$nbdm"; |
65 | | - } |
| 64 | + function getDefinedMeaningPerLanguage () { |
| 65 | + $dc = wdGetDataSetContext(); |
| 66 | + $dbr = wfGetDB( DB_SLAVE ); |
| 67 | + global $wgUploadPath ; |
66 | 68 | |
67 | | - function getDefinedMeaningPerLanguage () { |
68 | | - $dc = wdGetDataSetContext(); |
69 | | - $dbr = wfGetDB( DB_SLAVE ); |
70 | | - global $wgUploadPath ; |
| 69 | + $languageNames = getOwLanguageNames(); |
71 | 70 | |
72 | | - $languageNames = getOwLanguageNames(); |
| 71 | + // get number of DM with at least one translation for each language |
| 72 | + $sql = "SELECT language_id, count(DISTINCT {$dc}_syntrans.defined_meaning_id) as tot "; |
| 73 | + $sql .= " FROM {$dc}_expression, {$dc}_syntrans" ; |
| 74 | + $sql .= " WHERE {$dc}_expression.expression_id = {$dc}_syntrans.expression_id " ; |
| 75 | + $sql .= " AND {$dc}_syntrans.remove_transaction_id IS NULL " ; |
| 76 | + $sql .= " group by language_id " ; |
73 | 77 | |
74 | | - // get number of DM with at least one translation for each language |
75 | | - $sql = "SELECT language_id, count(DISTINCT {$dc}_syntrans.defined_meaning_id) as tot "; |
76 | | - $sql .= " FROM {$dc}_expression, {$dc}_syntrans" ; |
77 | | - $sql .= " WHERE {$dc}_expression.expression_id = {$dc}_syntrans.expression_id " ; |
78 | | - $sql .= " AND {$dc}_syntrans.remove_transaction_id IS NULL " ; |
79 | | - $sql .= " group by language_id " ; |
| 78 | + $queryResult = $dbr->query( $sql ); |
| 79 | + $nbDMArray = array () ; |
80 | 80 | |
81 | | - $queryResult = $dbr->query( $sql ); |
82 | | - $nbDMArray = array () ; |
| 81 | + while ( $row = $dbr->fetchObject( $queryResult ) ) { |
| 82 | + $lang = $languageNames[$row->language_id] ; |
| 83 | + $nbDMArray[$lang] = $row->tot ; |
| 84 | + } |
| 85 | + $nblang = count ( $nbDMArray ) ; |
| 86 | + $nbdm = $this->getNumberOfDM() ; |
83 | 87 | |
84 | | - while ( $row = $dbr->fetchObject( $queryResult ) ) { |
85 | | - $lang = $languageNames[$row->language_id] ; |
86 | | - $nbDMArray[$lang] = $row->tot ; |
87 | | - } |
88 | | - $nblang = count ( $nbDMArray ) ; |
89 | | - $nbdm = $this->getNumberOfDM() ; |
| 88 | + $tableLang = "<center><table class=\"sortable\">" ; |
| 89 | + $tableLang .= "<tr><th><b>" . wfMsg('ow_Language') . "</b></th><th><b>" . wfMsg('ow_DefinedMeaning') . "</b></th></tr>\n"; |
90 | 90 | |
91 | | - $tableLang = "<center><table class=\"sortable\">" ; |
92 | | - $tableLang .= "<tr><th><b>" . wfMsg('ow_Language') . "</b></th><th><b>" . wfMsg('ow_DefinedMeaning') . "</b></th></tr>\n"; |
| 91 | + arsort ( $nbDMArray ) ; |
| 92 | + $max = max ( $nbDMArray ) ; |
93 | 93 | |
94 | | - arsort ( $nbDMArray ) ; |
95 | | - $max = max ( $nbDMArray ) ; |
| 94 | + foreach ($nbDMArray as $lang => $dm) { |
| 95 | + $wi = ceil( ( ( $dm / $max ) * 500 ) ); |
| 96 | + $per = ceil( ( ( $dm / $max ) * 100 ) ); |
| 97 | + $tableLang .= "<tr><td>$lang</td><td align=right>$dm</td><td><img src=\"$wgUploadPath/sc1.png\" width=\"$wi\" height=15> $per % </td></tr>\n" ; |
| 98 | + } |
96 | 99 | |
97 | | - foreach ($nbDMArray as $lang => $dm) { |
98 | | - $wi = ceil( ( ( $dm / $max ) * 500 ) ); |
99 | | - $per = ceil( ( ( $dm / $max ) * 100 ) ); |
100 | | - $tableLang .= "<tr><td>$lang</td><td align=right>$dm</td><td><img src=\"$wgUploadPath/sc1.png\" width=\"$wi\" height=15> $per % </td></tr>\n" ; |
101 | | - } |
| 100 | + $tableLang .= "</table></center>" ; |
102 | 101 | |
103 | | - $tableLang .= "</table></center>" ; |
| 102 | + $output = "<center><big><table><tr><td>" . wfMsg('ow_DefinedMeaning') . " : </td><td><b>$nbdm</b></td></tr>" ; |
| 103 | + $output .= "<tr><td>" . wfMsg('ow_Language') . " : </td><td><b>$nblang</b></td></tr></table></big></center>" ; |
104 | 104 | |
105 | | - $output = "<center><big><table><tr><td>" . wfMsg('ow_DefinedMeaning') . " : </td><td><b>$nbdm</b></td></tr>" ; |
106 | | - $output .= "<tr><td>" . wfMsg('ow_Language') . " : </td><td><b>$nblang</b></td></tr></table></big></center>" ; |
| 105 | + $output .= "<p>$tableLang</p>" ; |
107 | 106 | |
108 | | - $output .= "<p>$tableLang</p>" ; |
| 107 | + return $output ; |
| 108 | + } |
109 | 109 | |
110 | | - return $output ; |
111 | | - } |
112 | 110 | |
| 111 | + function getDefinitionPerLanguage () { |
| 112 | + $dc = wdGetDataSetContext(); |
| 113 | + $dbr = wfGetDB( DB_SLAVE ); |
| 114 | + global $wgUploadPath ; |
113 | 115 | |
114 | | - function getDefinitionPerLanguage () { |
115 | | - $dc = wdGetDataSetContext(); |
116 | | - $dbr = wfGetDB( DB_SLAVE ); |
117 | | - global $wgUploadPath ; |
| 116 | + $languageNames = getOwLanguageNames(); |
118 | 117 | |
119 | | - $languageNames = getOwLanguageNames(); |
| 118 | + // get number of definitions for each language (note : a definition is always unique ) |
| 119 | + $sql = "SELECT language_id, count(DISTINCT {$dc}_translated_content.text_id) as tot "; |
| 120 | + $sql .= " FROM {$dc}_translated_content, {$dc}_defined_meaning" ; |
| 121 | + $sql .= " WHERE {$dc}_translated_content.translated_content_id = {$dc}_defined_meaning.meaning_text_tcid " ; |
| 122 | + $sql .= " AND {$dc}_translated_content.remove_transaction_id IS NULL " ; |
| 123 | + $sql .= " AND {$dc}_defined_meaning.remove_transaction_id IS NULL " ; |
| 124 | + $sql .= " group by language_id " ; |
120 | 125 | |
121 | | - // get number of definitions for each language (note : a definition is always unique ) |
122 | | - $sql = "SELECT language_id, count(DISTINCT {$dc}_translated_content.text_id) as tot "; |
123 | | - $sql .= " FROM {$dc}_translated_content, {$dc}_defined_meaning" ; |
124 | | - $sql .= " WHERE {$dc}_translated_content.translated_content_id = {$dc}_defined_meaning.meaning_text_tcid " ; |
125 | | - $sql .= " AND {$dc}_translated_content.remove_transaction_id IS NULL " ; |
126 | | - $sql .= " AND {$dc}_defined_meaning.remove_transaction_id IS NULL " ; |
127 | | - $sql .= " group by language_id " ; |
| 126 | + $queryResult = $dbr->query( $sql ); |
| 127 | + $nbDefArray = array () ; |
128 | 128 | |
129 | | - $queryResult = $dbr->query( $sql ); |
130 | | - $nbDefArray = array () ; |
| 129 | + while ( $row = $dbr->fetchObject( $queryResult ) ) { |
| 130 | + $lang = $languageNames[$row->language_id] ; |
| 131 | + $nbDefArray[$lang] = $row->tot ; |
| 132 | + } |
| 133 | + $nbDefTot = array_sum ( $nbDefArray ) ; |
| 134 | + $nblang = count ( $nbDefArray ) ; |
| 135 | + $nbdm = $this->getNumberOfDM() ; |
131 | 136 | |
132 | | - while ( $row = $dbr->fetchObject( $queryResult ) ) { |
133 | | - $lang = $languageNames[$row->language_id] ; |
134 | | - $nbDefArray[$lang] = $row->tot ; |
135 | | - } |
136 | | - $nbDefTot = array_sum ( $nbDefArray ) ; |
137 | | - $nblang = count ( $nbDefArray ) ; |
138 | | - $nbdm = $this->getNumberOfDM() ; |
| 137 | + $tableLang = "<center><table class=\"sortable\">" ; |
| 138 | + $tableLang .= "<tr><th><b>" . wfMsg('ow_Language') . "</b></th><th><b>" . wfMsg('ow_Definition') . "</b></th></tr>\n"; |
139 | 139 | |
140 | | - $tableLang = "<center><table class=\"sortable\">" ; |
141 | | - $tableLang .= "<tr><th><b>" . wfMsg('ow_Language') . "</b></th><th><b>" . wfMsg('ow_Definition') . "</b></th></tr>\n"; |
| 140 | + arsort ( $nbDefArray ) ; |
| 141 | + $max = max ( $nbDefArray ) ; |
| 142 | + foreach ($nbDefArray as $lang => $def) { |
| 143 | + $wi = ceil( ( ( $def / $max ) * 500 ) ); |
| 144 | + $per = ceil( ( ( $def / $max ) * 100 ) ); |
| 145 | + $tableLang .= "<tr><td>$lang</td><td align=right>$def</td><td><img src=\"$wgUploadPath/sc1.png\" width=\"$wi\" height=15> $per % </td></tr>\n" ; |
| 146 | + } |
142 | 147 | |
143 | | - arsort ( $nbDefArray ) ; |
144 | | - $max = max ( $nbDefArray ) ; |
145 | | - foreach ($nbDefArray as $lang => $def) { |
146 | | - $wi = ceil( ( ( $def / $max ) * 500 ) ); |
147 | | - $per = ceil( ( ( $def / $max ) * 100 ) ); |
148 | | - $tableLang .= "<tr><td>$lang</td><td align=right>$def</td><td><img src=\"$wgUploadPath/sc1.png\" width=\"$wi\" height=15> $per % </td></tr>\n" ; |
149 | | - } |
| 148 | + $tableLang .= "</table></center>" ; |
150 | 149 | |
151 | | - $tableLang .= "</table></center>" ; |
| 150 | + $output = "<center><big><table><tr><td>" . wfMsg('ow_Definition') . " : </td><td><b>$nbDefTot</b></td></tr>" ; |
| 151 | + $output .= "<tr><td>" . wfMsg('ow_DefinedMeaning') . " : </td><td><b>$nbdm</b></td></tr>" ; |
| 152 | + $output .= "<tr><td>" . wfMsg('ow_Language') . " : </td><td><b>$nblang</b></td></tr></table></big></center>" ; |
152 | 153 | |
153 | | - $output = "<center><big><table><tr><td>" . wfMsg('ow_Definition') . " : </td><td><b>$nbDefTot</b></td></tr>" ; |
154 | | - $output .= "<tr><td>" . wfMsg('ow_DefinedMeaning') . " : </td><td><b>$nbdm</b></td></tr>" ; |
155 | | - $output .= "<tr><td>" . wfMsg('ow_Language') . " : </td><td><b>$nblang</b></td></tr></table></big></center>" ; |
| 154 | + $output .= "<p>$tableLang</p>" ; |
156 | 155 | |
157 | | - $output .= "<p>$tableLang</p>" ; |
| 156 | + return $output ; |
| 157 | + } |
158 | 158 | |
159 | | - return $output ; |
160 | | - } |
161 | 159 | |
| 160 | + function getExpressionPerLanguage () { |
| 161 | + $dc = wdGetDataSetContext(); |
| 162 | + $dbr = wfGetDB( DB_SLAVE ); |
| 163 | + global $wgUploadPath ; |
162 | 164 | |
163 | | - function getExpressionPerLanguage () { |
164 | | - $dc = wdGetDataSetContext(); |
165 | | - $dbr = wfGetDB( DB_SLAVE ); |
166 | | - global $wgUploadPath ; |
| 165 | + $sql = "SELECT language_id, count(DISTINCT {$dc}_expression.expression_id) as tot "; |
| 166 | + $sql .= " FROM {$dc}_expression, {$dc}_syntrans" ; |
| 167 | + $sql .= " WHERE {$dc}_expression.expression_id = {$dc}_syntrans.expression_id " ; |
| 168 | + $sql .= " AND {$dc}_syntrans.remove_transaction_id IS NULL " ; |
| 169 | + $sql .= " group by language_id " ; |
167 | 170 | |
168 | | - $sql = "SELECT language_id, count(DISTINCT {$dc}_expression.expression_id) as tot "; |
169 | | - $sql .= " FROM {$dc}_expression, {$dc}_syntrans" ; |
170 | | - $sql .= " WHERE {$dc}_expression.expression_id = {$dc}_syntrans.expression_id " ; |
171 | | - $sql .= " AND {$dc}_syntrans.remove_transaction_id IS NULL " ; |
172 | | - $sql .= " group by language_id " ; |
| 171 | + $queryResult = $dbr->query( $sql ); |
173 | 172 | |
174 | | - $queryResult = $dbr->query( $sql ); |
| 173 | + $languageNames = getOwLanguageNames(); |
| 174 | + $nbexpArray = array () ; |
175 | 175 | |
176 | | - $languageNames = getOwLanguageNames(); |
177 | | - $nbexpArray = array () ; |
| 176 | + while ( $row = $dbr->fetchObject( $queryResult ) ) { |
| 177 | + $lang = $languageNames[$row->language_id] ; |
| 178 | + $nbexpArray[$lang] = $row->tot ; |
| 179 | + } |
| 180 | + $nbexptot = array_sum ( $nbexpArray ) ; |
| 181 | + $nbdm = $this->getNumberOfDM() ; |
| 182 | + $nblang = count ( $nbexpArray ) ; |
178 | 183 | |
179 | | - while ( $row = $dbr->fetchObject( $queryResult ) ) { |
180 | | - $lang = $languageNames[$row->language_id] ; |
181 | | - $nbexpArray[$lang] = $row->tot ; |
182 | | - } |
183 | | - $nbexptot = array_sum ( $nbexpArray ) ; |
184 | | - $nbdm = $this->getNumberOfDM() ; |
185 | | - $nblang = count ( $nbexpArray ) ; |
| 184 | + $tableLang = "<center><table class=\"sortable\">" ; |
| 185 | + $tableLang .= "<tr><th><b>" . wfMsg('ow_Language') . "</b></th><th><b>" . wfMsg('ow_Expression') . "</b></th></tr>\n"; |
186 | 186 | |
187 | | - $tableLang = "<center><table class=\"sortable\">" ; |
188 | | - $tableLang .= "<tr><th><b>" . wfMsg('ow_Language') . "</b></th><th><b>" . wfMsg('ow_Expression') . "</b></th></tr>\n"; |
| 187 | + arsort ( $nbexpArray ) ; |
| 188 | + $max = max ( $nbexpArray ) ; |
| 189 | + foreach ($nbexpArray as $lang => $exp) { |
| 190 | + $wi = ceil( ( ( $exp / $max ) * 500 ) ); |
| 191 | + $per = ceil( ( ( $exp / $max ) * 100 ) ); |
| 192 | + $tableLang .= "<tr><td>$lang</td><td align=right>$exp</td><td><img src=\"$wgUploadPath/sc1.png\" width=\"$wi\" height=15> $per % </td></tr>\n" ; |
| 193 | + } |
189 | 194 | |
190 | | - arsort ( $nbexpArray ) ; |
191 | | - $max = max ( $nbexpArray ) ; |
192 | | - foreach ($nbexpArray as $lang => $exp) { |
193 | | - $wi = ceil( ( ( $exp / $max ) * 500 ) ); |
194 | | - $per = ceil( ( ( $exp / $max ) * 100 ) ); |
195 | | - $tableLang .= "<tr><td>$lang</td><td align=right>$exp</td><td><img src=\"$wgUploadPath/sc1.png\" width=\"$wi\" height=15> $per % </td></tr>\n" ; |
196 | | - } |
| 195 | + $tableLang .= "</table></center>" ; |
197 | 196 | |
198 | | - $tableLang .= "</table></center>" ; |
| 197 | + $output = "<center><big><table><tr><td>" . wfMsg('ow_Expression') . " : </td><td><b>$nbexptot</b></td></tr>" ; |
| 198 | + $output .= "<tr><td>" . wfMsg('ow_DefinedMeaning') . " : </td><td><b>$nbdm</b></td></tr>" ; |
| 199 | + $output .= "<tr><td>" . wfMsg('ow_Language') . " : </td><td><b>$nblang</b></td></tr></table></big></center>" ; |
199 | 200 | |
200 | | - $output = "<center><big><table><tr><td>" . wfMsg('ow_Expression') . " : </td><td><b>$nbexptot</b></td></tr>" ; |
201 | | - $output .= "<tr><td>" . wfMsg('ow_DefinedMeaning') . " : </td><td><b>$nbdm</b></td></tr>" ; |
202 | | - $output .= "<tr><td>" . wfMsg('ow_Language') . " : </td><td><b>$nblang</b></td></tr></table></big></center>" ; |
| 201 | + $output .= "<p>$tableLang</p>" ; |
| 202 | + return $output ; |
| 203 | + } |
203 | 204 | |
204 | | - $output .= "<p>$tableLang</p>" ; |
205 | | - return $output ; |
206 | | - } |
207 | 205 | |
| 206 | + function getSyntransPerLanguage () { |
| 207 | + $dc = wdGetDataSetContext(); |
| 208 | + $dbr = wfGetDB( DB_SLAVE ); |
| 209 | + global $wgUploadPath ; |
208 | 210 | |
209 | | - function getSyntransPerLanguage () { |
210 | | - $dc = wdGetDataSetContext(); |
211 | | - $dbr = wfGetDB( DB_SLAVE ); |
212 | | - global $wgUploadPath ; |
| 211 | + $sql = "SELECT language_id, count(DISTINCT {$dc}_syntrans.syntrans_sid) as tot "; |
| 212 | + $sql .= " FROM {$dc}_expression, {$dc}_syntrans" ; |
| 213 | + $sql .= " WHERE {$dc}_expression.expression_id = {$dc}_syntrans.expression_id " ; |
| 214 | + $sql .= " AND {$dc}_syntrans.remove_transaction_id IS NULL " ; |
| 215 | + $sql .= " group by language_id " ; |
213 | 216 | |
214 | | - $sql = "SELECT language_id, count(DISTINCT {$dc}_syntrans.syntrans_sid) as tot "; |
215 | | - $sql .= " FROM {$dc}_expression, {$dc}_syntrans" ; |
216 | | - $sql .= " WHERE {$dc}_expression.expression_id = {$dc}_syntrans.expression_id " ; |
217 | | - $sql .= " AND {$dc}_syntrans.remove_transaction_id IS NULL " ; |
218 | | - $sql .= " group by language_id " ; |
| 217 | + $queryResult = $dbr->query( $sql ); |
219 | 218 | |
220 | | - $queryResult = $dbr->query( $sql ); |
| 219 | + $languageNames = getOwLanguageNames(); |
221 | 220 | |
222 | | - $languageNames = getOwLanguageNames(); |
| 221 | + $nblang = 0 ; |
| 222 | + $nbexptot = 0 ; |
| 223 | + $nbSyntransArray = array () ; |
223 | 224 | |
224 | | - $nblang = 0 ; |
225 | | - $nbexptot = 0 ; |
226 | | - $nbSyntransArray = array () ; |
| 225 | + while ( $row = $dbr->fetchObject( $queryResult ) ) { |
| 226 | + $lang = $languageNames[$row->language_id] ; |
| 227 | + $nbSyntransArray[$lang] = $row->tot ; |
| 228 | + } |
| 229 | + $nbSyntransTot = array_sum ( $nbSyntransArray ) ; |
| 230 | + $nbdm = $this->getNumberOfDM() ; |
| 231 | + $nblang = count ( $nbSyntransArray ) ; |
227 | 232 | |
228 | | - while ( $row = $dbr->fetchObject( $queryResult ) ) { |
229 | | - $lang = $languageNames[$row->language_id] ; |
230 | | - $nbSyntransArray[$lang] = $row->tot ; |
231 | | - } |
232 | | - $nbSyntransTot = array_sum ( $nbSyntransArray ) ; |
233 | | - $nbdm = $this->getNumberOfDM() ; |
234 | | - $nblang = count ( $nbSyntransArray ) ; |
| 233 | + $tableLang = "<center><table class=\"sortable\">" ; |
| 234 | + $tableLang .= "<tr><th><b>" . wfMsg('ow_Language') . "</b></th><th><b>Syntrans</b></th></tr>\n"; |
235 | 235 | |
236 | | - $tableLang = "<center><table class=\"sortable\">" ; |
237 | | - $tableLang .= "<tr><th><b>" . wfMsg('ow_Language') . "</b></th><th><b>Syntrans</b></th></tr>\n"; |
| 236 | + arsort ( $nbSyntransArray ) ; |
| 237 | + $max = max ( $nbSyntransArray ) ; |
| 238 | + foreach ($nbSyntransArray as $lang => $syntrans) { |
| 239 | + $wi = ceil( ( ( $syntrans / $max ) * 500 ) ); |
| 240 | + $per = ceil( ( ( $syntrans / $max ) * 100 ) ); |
| 241 | + $tableLang .= "<tr><td>$lang</td><td align=right>$syntrans</td><td><img src=\"$wgUploadPath/sc1.png\" width=\"$wi\" height=15> $per % </td></tr>\n" ; |
| 242 | + } |
238 | 243 | |
239 | | - arsort ( $nbSyntransArray ) ; |
240 | | - $max = max ( $nbSyntransArray ) ; |
241 | | - foreach ($nbSyntransArray as $lang => $syntrans) { |
242 | | - $wi = ceil( ( ( $syntrans / $max ) * 500 ) ); |
243 | | - $per = ceil( ( ( $syntrans / $max ) * 100 ) ); |
244 | | - $tableLang .= "<tr><td>$lang</td><td align=right>$syntrans</td><td><img src=\"$wgUploadPath/sc1.png\" width=\"$wi\" height=15> $per % </td></tr>\n" ; |
245 | | - } |
| 244 | + $tableLang .= "</table></center>" ; |
246 | 245 | |
247 | | - $tableLang .= "</table></center>" ; |
| 246 | + $output = "<center><big><table><tr><td>Syntrans : </td><td><b>$nbSyntransTot</b></td></tr>" ; |
| 247 | + $output .= "<tr><td>" . wfMsg('ow_DefinedMeaning') . " : </td><td><b>$nbdm</b></td></tr>" ; |
| 248 | + $output .= "<tr><td>" . wfMsg('ow_Language') . " : </td><td><b>$nblang</b></td></tr></table></big></center>" ; |
248 | 249 | |
249 | | - $output = "<center><big><table><tr><td>Syntrans : </td><td><b>$nbSyntransTot</b></td></tr>" ; |
250 | | - $output .= "<tr><td>" . wfMsg('ow_DefinedMeaning') . " : </td><td><b>$nbdm</b></td></tr>" ; |
251 | | - $output .= "<tr><td>" . wfMsg('ow_Language') . " : </td><td><b>$nblang</b></td></tr></table></big></center>" ; |
| 250 | + $output .= "<p>$tableLang</p>" ; |
252 | 251 | |
253 | | - $output .= "<p>$tableLang</p>" ; |
254 | | - |
255 | | - return $output ; |
256 | | - } |
257 | | - |
258 | | - } |
259 | | - SpecialPage::addPage( new SpecialOWStatistics ); |
260 | | - |
| 252 | + return $output ; |
261 | 253 | } |
| 254 | + |
| 255 | +} |
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialImportTSV.php |
— | — | @@ -1,245 +1,236 @@ |
2 | 2 | <?php |
3 | | - if ( !defined( 'MEDIAWIKI' ) ) die(); |
| 3 | +if ( !defined( 'MEDIAWIKI' ) ) die(); |
4 | 4 | |
5 | | - require_once( "WikiDataAPI.php" ); // for bootstrapCollection |
6 | | - require_once( "Utilities.php" ); |
| 5 | +require_once( "WikiDataAPI.php" ); // for bootstrapCollection |
| 6 | +require_once( "Utilities.php" ); |
| 7 | + |
| 8 | +class SpecialImportTSV extends SpecialPage { |
7 | 9 | |
8 | | - $wgGroupPermissions['bureaucrat']['importtsv'] = true; |
9 | | - $wgAvailableRights[] = 'importtsv'; |
10 | | - $wgExtensionFunctions[] = 'wfSpecialImportTSV'; |
| 10 | + function SpecialImportTSV() { |
| 11 | + parent::__construct( 'ImportTSV' ); |
| 12 | + } |
11 | 13 | |
12 | | - function wfSpecialImportTSV() { |
13 | | - class SpecialImportTSV extends SpecialPage { |
14 | | - |
15 | | - function SpecialImportTSV() { |
16 | | - parent::__construct( 'ImportTSV' ); |
17 | | - } |
| 14 | + function execute( $par ) { |
18 | 15 | |
19 | | - function execute( $par ) { |
| 16 | + global $wgOut, $wgUser, $wgRequest; |
20 | 17 | |
21 | | - global $wgOut, $wgUser, $wgRequest; |
| 18 | + $wgOut->setPageTitle( wfMsg( 'ow_importtsv_title1' ) ); |
| 19 | + if ( !$wgUser->isAllowed( 'importtsv' ) ) { |
| 20 | + $wgOut->addHTML( wfMsg( 'ow_importtsv_not_allowed' ) ); |
| 21 | + return false; |
| 22 | + } |
| 23 | + |
| 24 | + $dbr = wfGetDB( DB_MASTER ); |
| 25 | + $dc = wdGetDataSetcontext(); |
| 26 | + $wgOut->setPageTitle( wfMsg( 'ow_importtsv_importing' ) ); |
| 27 | + setlocale( LC_ALL, 'en_US.UTF-8' ); |
| 28 | + if ( $wgRequest->getFileName( 'tsvfile' ) ) { |
| 29 | + |
| 30 | + // ***************** |
| 31 | + // process tsv |
| 32 | + // ***************** |
22 | 33 | |
23 | | - $wgOut->setPageTitle( wfMsg( 'ow_importtsv_title1' ) ); |
24 | | - if ( !$wgUser->isAllowed( 'importtsv' ) ) { |
25 | | - $wgOut->addHTML( wfMsg( 'ow_importtsv_not_allowed' ) ); |
| 34 | + require_once( 'WikiDataAPI.php' ); |
| 35 | + require_once( 'Transaction.php' ); |
| 36 | + |
| 37 | + $testRun = $wgRequest->getCheck( 'testrun' ); |
| 38 | + |
| 39 | + // lets do some tests first. Is this even a tsv file? |
| 40 | + // It is _very_ important that the file is utf-8 encoded. |
| 41 | + // also, this is a good time to determine the max line length for the |
| 42 | + // fgetcsv function. |
| 43 | + $file = fopen( $wgRequest->getFileTempname( 'tsvfile' ), 'r' ); |
| 44 | + $myLine = ""; |
| 45 | + $maxLineLength = 0; |
| 46 | + while ( $myLine = fgets( $file ) ) { |
| 47 | + if ( !preg_match( '/./u', $myLine ) ) { |
| 48 | + $wgOut->setPageTitle( wfMsg( 'ow_importtsv_import_failed' ) ); |
| 49 | + $wgOut->addHTML( wfMsg( 'ow_importtsv_not_utf8' ) ); |
26 | 50 | return false; |
27 | 51 | } |
| 52 | + $maxLineLength = max( $maxLineLength, strlen( $myLine ) + 2 ); |
| 53 | + } |
| 54 | + |
| 55 | + // start from the beginning again. Check if the column names are valid |
| 56 | + rewind( $file ); |
| 57 | + $columns = fgetcsv( $file, $maxLineLength, "\t" ); |
| 58 | + // somehow testing for $columns[0] fails sometimes. Byte Order Mark? |
| 59 | + if ( !$columns || count( $columns ) <= 2 || $columns[1] != "defining expression" ) { |
| 60 | + $wgOut->setPageTitle( wfMsg( 'ow_importtsv_import_failed' ) ); |
| 61 | + $wgOut->addHTML( wfMsg( 'ow_importtsv_not_tsv' ) ); |
| 62 | + return false; |
| 63 | + } |
| 64 | + for ( $i = 2; $i < count( $columns ); $i++ ) { |
| 65 | + $columnName = $columns[$i]; |
| 66 | + $baseName = substr( $columnName, 0, strrpos( $columnName, '_' ) ); |
| 67 | + if ( $baseName == "definition" || $baseName == "translations" ) { |
| 68 | + $langCode = substr( $columnName, strrpos( $columnName, '_' ) + 1 ); |
| 69 | + if ( !getLanguageIdForIso639_3( $langCode ) ) { |
| 70 | + $wgOut->setPageTitle( wfMsg( 'ow_importtsv_import_failed' ) ); |
| 71 | + $wgOut->addHTML( wfMsg( 'ow_impexptsv_unknown_lang', $langCode ) ); |
| 72 | + return false; |
| 73 | + } |
| 74 | + } |
| 75 | + else { // column name does not start with definition or translations. |
| 76 | + $wgOut->setPageTitle( wfMsg( 'ow_importtsv_import_failed' ) ); |
| 77 | + $wgOut->addHTML( wfMsg( 'ow_importtsv_bad_columns', $columnName ) ); |
| 78 | + return false; |
| 79 | + } |
28 | 80 | |
29 | | - $dbr = wfGetDB( DB_MASTER ); |
30 | | - $dc = wdGetDataSetcontext(); |
| 81 | + } |
| 82 | + |
| 83 | + |
| 84 | + // |
| 85 | + // All tests passed. lets get started |
| 86 | + // |
| 87 | + |
| 88 | + if ( $testRun ) { |
| 89 | + $wgOut->setPageTitle( wfMsg( 'ow_importtsv_test_run_title' ) ); |
| 90 | + } |
| 91 | + else { |
31 | 92 | $wgOut->setPageTitle( wfMsg( 'ow_importtsv_importing' ) ); |
32 | | - setlocale( LC_ALL, 'en_US.UTF-8' ); |
33 | | - if ( $wgRequest->getFileName( 'tsvfile' ) ) { |
34 | | - |
35 | | - // ***************** |
36 | | - // process tsv |
37 | | - // ***************** |
| 93 | + } |
| 94 | + |
| 95 | + startNewTransaction( $wgUser->getID(), wfGetIP(), "Bulk import via Special:ImportTSV", $dc ); # this string shouldn't be localized because it will be stored in the db |
38 | 96 | |
39 | | - require_once( 'WikiDataAPI.php' ); |
40 | | - require_once( 'Transaction.php' ); |
| 97 | + $row = ""; |
| 98 | + $line = 1; // actually 2, 1 was the header, but increased at the start of while |
| 99 | + $definitions = 0; // definitions added |
| 100 | + $translations = 0; // translations added |
| 101 | + |
| 102 | + while ( $row = fgetcsv( $file, $maxLineLength, "\t" ) ) { |
| 103 | + $line++; |
| 104 | + |
| 105 | + $dmid = $row[0]; |
| 106 | + $exp = $row[1]; |
| 107 | + |
| 108 | + // find the defined meaning record |
| 109 | + $qry = "SELECT dm.meaning_text_tcid, exp.spelling "; |
| 110 | + $qry .= "FROM {$dc}_defined_meaning dm INNER JOIN {$dc}_expression exp ON dm.expression_id=exp.expression_id "; |
| 111 | + $qry .= "WHERE dm.defined_meaning_id=$dmid "; |
| 112 | + $qry .= "AND " . getLatestTransactionRestriction( 'dm' ); |
| 113 | + $qry .= "AND " . getLatestTransactionRestriction( 'exp' ); |
| 114 | + |
| 115 | + $dmResult = $dbr->query( $qry ); |
| 116 | + $dmRecord = null; |
| 117 | + // perfomr some tests |
| 118 | + if ( $dmRecord = $dbr->fetchRow( $dmResult ) ) { |
| 119 | + if ( $dmRecord['spelling'] != $exp ) { |
| 120 | + $wgOut->addHTML( "Skipped line $line: defined meaning id $dmid does not match defining expression. Should be '{$dmRecord['spelling']}', found '$exp'.<br />" ); |
| 121 | + continue; |
| 122 | + } |
| 123 | + } |
| 124 | + else { |
| 125 | + $wgOut->addHTML( "Skipped line $line: unknown defined meaning id $dmid. The id may have been altered in the imported file, or the defined meaning or defining expression was removed from the database.<br />" ); |
| 126 | + continue; |
| 127 | + } |
| 128 | + |
| 129 | + |
| 130 | + // all is well. Get the translated content id |
| 131 | + $tcid = $dmRecord['meaning_text_tcid']; |
| 132 | + |
| 133 | + |
| 134 | + for ( $columnIndex = 2; $columnIndex < count( $columns ); $columnIndex++ ) { |
41 | 135 | |
42 | | - $testRun = $wgRequest->getCheck( 'testrun' ); |
43 | | - |
44 | | - // lets do some tests first. Is this even a tsv file? |
45 | | - // It is _very_ important that the file is utf-8 encoded. |
46 | | - // also, this is a good time to determine the max line length for the |
47 | | - // fgetcsv function. |
48 | | - $file = fopen( $wgRequest->getFileTempname( 'tsvfile' ), 'r' ); |
49 | | - $myLine = ""; |
50 | | - $maxLineLength = 0; |
51 | | - while ( $myLine = fgets( $file ) ) { |
52 | | - if ( !preg_match( '/./u', $myLine ) ) { |
53 | | - $wgOut->setPageTitle( wfMsg( 'ow_importtsv_import_failed' ) ); |
54 | | - $wgOut->addHTML( wfMsg( 'ow_importtsv_not_utf8' ) ); |
55 | | - return false; |
56 | | - } |
57 | | - $maxLineLength = max( $maxLineLength, strlen( $myLine ) + 2 ); |
| 136 | + // Google docs removes empty columns at the end of a row, |
| 137 | + // so if column index is higher than the length of the row, we can break |
| 138 | + // and move on to the next defined meaning. |
| 139 | + if ( columnIndex >= count( $row ) ) { |
| 140 | + break; |
58 | 141 | } |
59 | 142 | |
60 | | - // start from the beginning again. Check if the column names are valid |
61 | | - rewind( $file ); |
62 | | - $columns = fgetcsv( $file, $maxLineLength, "\t" ); |
63 | | - // somehow testing for $columns[0] fails sometimes. Byte Order Mark? |
64 | | - if ( !$columns || count( $columns ) <= 2 || $columns[1] != "defining expression" ) { |
65 | | - $wgOut->setPageTitle( wfMsg( 'ow_importtsv_import_failed' ) ); |
66 | | - $wgOut->addHTML( wfMsg( 'ow_importtsv_not_tsv' ) ); |
67 | | - return false; |
| 143 | + $columnValue = $row[$columnIndex]; |
| 144 | + if ( !$columnValue ) { |
| 145 | + continue; |
68 | 146 | } |
69 | | - for ( $i = 2; $i < count( $columns ); $i++ ) { |
70 | | - $columnName = $columns[$i]; |
71 | | - $baseName = substr( $columnName, 0, strrpos( $columnName, '_' ) ); |
72 | | - if ( $baseName == "definition" || $baseName == "translations" ) { |
73 | | - $langCode = substr( $columnName, strrpos( $columnName, '_' ) + 1 ); |
74 | | - if ( !getLanguageIdForIso639_3( $langCode ) ) { |
75 | | - $wgOut->setPageTitle( wfMsg( 'ow_importtsv_import_failed' ) ); |
76 | | - $wgOut->addHTML( wfMsg( 'ow_impexptsv_unknown_lang', $langCode ) ); |
77 | | - return false; |
| 147 | + |
| 148 | + $columnName = $columns[$columnIndex]; |
| 149 | + $langCode = substr( $columnName, strrpos( $columnName, '_' ) + 1 ); |
| 150 | + $langId = getLanguageIdForIso639_3( $langCode ); |
| 151 | + if ( strpos( $columnName, 'definition' ) === 0 ) { |
| 152 | + if ( !translatedTextExists( $tcid, $langId ) ) { |
| 153 | + if ( $testRun ) { |
| 154 | + $wgOut->addHTML( "Would add definition for $exp ($dmid) in $langCode: $columnValue.<br />" ); |
| 155 | + } else { |
| 156 | + addTranslatedText( $tcid, $langId, $columnValue ); |
| 157 | + $wgOut->addHTML( "Added definition for $exp ($dmid) in $langCode: $columnValue.<br />" ); |
| 158 | + $definitions++; |
78 | 159 | } |
79 | 160 | } |
80 | | - else { // column name does not start with definition or translations. |
81 | | - $wgOut->setPageTitle( wfMsg( 'ow_importtsv_import_failed' ) ); |
82 | | - $wgOut->addHTML( wfMsg( 'ow_importtsv_bad_columns', $columnName ) ); |
83 | | - return false; |
84 | | - } |
85 | | - |
86 | 161 | } |
87 | | - |
88 | | - |
89 | | - // |
90 | | - // All tests passed. lets get started |
91 | | - // |
| 162 | + if ( strpos( $columnName, 'translation' ) === 0 ) { |
| 163 | + $spellings = explode( '|', $columnValue ); |
| 164 | + foreach ( $spellings as $spelling ) { |
| 165 | + $spelling = trim( $spelling ); |
| 166 | + $expression = findExpression( $spelling, $langId ); |
| 167 | + if ( !$expression ) { // expression does not exist |
| 168 | + if ( $testRun ) { |
| 169 | + $wgOut->addHTML( "Would add translation for $exp ($dmid) in $langCode: $spelling. Would also add new page.<br />" ); |
| 170 | + } |
| 171 | + else { |
| 172 | + $expression = createExpression( $spelling, $langId ); |
| 173 | + $expression->bindToDefinedMeaning( $dmid, 1 ); |
92 | 174 | |
93 | | - if ( $testRun ) { |
94 | | - $wgOut->setPageTitle( wfMsg( 'ow_importtsv_test_run_title' ) ); |
95 | | - } |
96 | | - else { |
97 | | - $wgOut->setPageTitle( wfMsg( 'ow_importtsv_importing' ) ); |
98 | | - } |
99 | | - |
100 | | - startNewTransaction( $wgUser->getID(), wfGetIP(), "Bulk import via Special:ImportTSV", $dc ); # this string shouldn't be localized because it will be stored in the db |
| 175 | + // not nescesary to check page exists, createPage does that. |
| 176 | + $title = getPageTitle( $spelling ); |
| 177 | + createPage( 16, $title ); |
101 | 178 | |
102 | | - $row = ""; |
103 | | - $line = 1; // actually 2, 1 was the header, but increased at the start of while |
104 | | - $definitions = 0; // definitions added |
105 | | - $translations = 0; // translations added |
106 | | - |
107 | | - while ( $row = fgetcsv( $file, $maxLineLength, "\t" ) ) { |
108 | | - $line++; |
109 | | - |
110 | | - $dmid = $row[0]; |
111 | | - $exp = $row[1]; |
112 | | - |
113 | | - // find the defined meaning record |
114 | | - $qry = "SELECT dm.meaning_text_tcid, exp.spelling "; |
115 | | - $qry .= "FROM {$dc}_defined_meaning dm INNER JOIN {$dc}_expression exp ON dm.expression_id=exp.expression_id "; |
116 | | - $qry .= "WHERE dm.defined_meaning_id=$dmid "; |
117 | | - $qry .= "AND " . getLatestTransactionRestriction( 'dm' ); |
118 | | - $qry .= "AND " . getLatestTransactionRestriction( 'exp' ); |
119 | | - |
120 | | - $dmResult = $dbr->query( $qry ); |
121 | | - $dmRecord = null; |
122 | | - // perfomr some tests |
123 | | - if ( $dmRecord = $dbr->fetchRow( $dmResult ) ) { |
124 | | - if ( $dmRecord['spelling'] != $exp ) { |
125 | | - $wgOut->addHTML( "Skipped line $line: defined meaning id $dmid does not match defining expression. Should be '{$dmRecord['spelling']}', found '$exp'.<br />" ); |
126 | | - continue; |
| 179 | + $wgOut->addHTML( "Added translation for $exp ($dmid) in $langCode: $spelling. Also added new page.<br />" ); |
| 180 | + $translations++; |
| 181 | + } |
127 | 182 | } |
128 | | - } |
129 | | - else { |
130 | | - $wgOut->addHTML( "Skipped line $line: unknown defined meaning id $dmid. The id may have been altered in the imported file, or the defined meaning or defining expression was removed from the database.<br />" ); |
131 | | - continue; |
132 | | - } |
133 | | - |
134 | | - |
135 | | - // all is well. Get the translated content id |
136 | | - $tcid = $dmRecord['meaning_text_tcid']; |
137 | | - |
138 | | - |
139 | | - for ( $columnIndex = 2; $columnIndex < count( $columns ); $columnIndex++ ) { |
140 | | - |
141 | | - // Google docs removes empty columns at the end of a row, |
142 | | - // so if column index is higher than the length of the row, we can break |
143 | | - // and move on to the next defined meaning. |
144 | | - if ( columnIndex >= count( $row ) ) { |
145 | | - break; |
146 | | - } |
147 | | - |
148 | | - $columnValue = $row[$columnIndex]; |
149 | | - if ( !$columnValue ) { |
150 | | - continue; |
151 | | - } |
152 | | - |
153 | | - $columnName = $columns[$columnIndex]; |
154 | | - $langCode = substr( $columnName, strrpos( $columnName, '_' ) + 1 ); |
155 | | - $langId = getLanguageIdForIso639_3( $langCode ); |
156 | | - if ( strpos( $columnName, 'definition' ) === 0 ) { |
157 | | - if ( !translatedTextExists( $tcid, $langId ) ) { |
| 183 | + else { // expression exists, but may not be bound to this defined meaning. |
| 184 | + if ( !$expression->isBoundToDefinedMeaning( $dmid ) ) { |
158 | 185 | if ( $testRun ) { |
159 | | - $wgOut->addHTML( "Would add definition for $exp ($dmid) in $langCode: $columnValue.<br />" ); |
160 | | - } else { |
161 | | - addTranslatedText( $tcid, $langId, $columnValue ); |
162 | | - $wgOut->addHTML( "Added definition for $exp ($dmid) in $langCode: $columnValue.<br />" ); |
163 | | - $definitions++; |
| 186 | + $wgOut->addHTML( "Would add translation for $exp ($dmid) in $langCode: $spelling.<br />" ); |
164 | 187 | } |
165 | | - } |
166 | | - } |
167 | | - if ( strpos( $columnName, 'translation' ) === 0 ) { |
168 | | - $spellings = explode( '|', $columnValue ); |
169 | | - foreach ( $spellings as $spelling ) { |
170 | | - $spelling = trim( $spelling ); |
171 | | - $expression = findExpression( $spelling, $langId ); |
172 | | - if ( !$expression ) { // expression does not exist |
173 | | - if ( $testRun ) { |
174 | | - $wgOut->addHTML( "Would add translation for $exp ($dmid) in $langCode: $spelling. Would also add new page.<br />" ); |
175 | | - } |
176 | | - else { |
177 | | - $expression = createExpression( $spelling, $langId ); |
178 | | - $expression->bindToDefinedMeaning( $dmid, 1 ); |
179 | | - |
180 | | - // not nescesary to check page exists, createPage does that. |
181 | | - $title = getPageTitle( $spelling ); |
182 | | - createPage( 16, $title ); |
183 | | - |
184 | | - $wgOut->addHTML( "Added translation for $exp ($dmid) in $langCode: $spelling. Also added new page.<br />" ); |
185 | | - $translations++; |
186 | | - } |
| 188 | + else { |
| 189 | + $expression->bindToDefinedMeaning( $dmid, 1 ); |
| 190 | + $wgOut->addHTML( "Added translation for $exp ($dmid) in $langCode: $spelling.<br />" ); |
| 191 | + $translations++; |
187 | 192 | } |
188 | | - else { // expression exists, but may not be bound to this defined meaning. |
189 | | - if ( !$expression->isBoundToDefinedMeaning( $dmid ) ) { |
190 | | - if ( $testRun ) { |
191 | | - $wgOut->addHTML( "Would add translation for $exp ($dmid) in $langCode: $spelling.<br />" ); |
192 | | - } |
193 | | - else { |
194 | | - $expression->bindToDefinedMeaning( $dmid, 1 ); |
195 | | - $wgOut->addHTML( "Added translation for $exp ($dmid) in $langCode: $spelling.<br />" ); |
196 | | - $translations++; |
197 | | - } |
198 | | - } |
199 | | - } |
200 | 193 | } |
201 | 194 | } |
202 | 195 | } |
203 | 196 | } |
204 | | - |
205 | | - if ( $definitions == 0 && $translations == 0 ) { |
206 | | - $wgOut->addHTML( "<br />" ); |
207 | | - if ( $testRun ) { |
208 | | - $wgOut->addHTML( wfMsg( 'ow_importtsv_nothing_added_test' ) ); |
209 | | - } |
210 | | - else { |
211 | | - $wgOut->addHTML( wfMsg( 'ow_importtsv_nothing_added' ) ); |
212 | | - } |
213 | | - $wgOut->addHTML( "<br />" ); |
214 | | - } |
215 | | - else { |
216 | | - $wgOut->addHTML( "<br />" . wfMsgExt( 'ow_importtsv_results', 'parsemag', $definitions, $translations ) . "<br />" ); |
217 | | - } |
218 | | - |
219 | 197 | } |
| 198 | + } |
| 199 | + |
| 200 | + if ( $definitions == 0 && $translations == 0 ) { |
| 201 | + $wgOut->addHTML( "<br />" ); |
| 202 | + if ( $testRun ) { |
| 203 | + $wgOut->addHTML( wfMsg( 'ow_importtsv_nothing_added_test' ) ); |
| 204 | + } |
220 | 205 | else { |
221 | | - // render the page |
222 | | - $wgOut->setPageTitle( wfMsg( 'ow_importtsv_title2' ) ); |
223 | | - $wgOut->addHTML( wfMsg( 'ow_importtsv_header' ) ); |
224 | | - |
225 | | - $wgOut->addHTML( getOptionPanelForFileUpload( |
226 | | - array( |
227 | | - wfMsg( 'ow_importtsv_file' ) => getFileField( 'tsvfile' ), |
228 | | - wfMsg( 'ow_importtsv_test_run' ) => getCheckBox( 'testrun', true ) |
229 | | - ) |
230 | | - ) ); |
| 206 | + $wgOut->addHTML( wfMsg( 'ow_importtsv_nothing_added' ) ); |
231 | 207 | } |
232 | | - |
| 208 | + $wgOut->addHTML( "<br />" ); |
233 | 209 | } |
234 | | - |
235 | | - |
236 | | - /* HELPER METHODS START HERE */ |
237 | | - |
238 | | - function getLanguage( $columnName ) { |
239 | | - |
| 210 | + else { |
| 211 | + $wgOut->addHTML( "<br />" . wfMsgExt( 'ow_importtsv_results', 'parsemag', $definitions, $translations ) . "<br />" ); |
240 | 212 | } |
| 213 | + |
| 214 | + } |
| 215 | + else { |
| 216 | + // render the page |
| 217 | + $wgOut->setPageTitle( wfMsg( 'ow_importtsv_title2' ) ); |
| 218 | + $wgOut->addHTML( wfMsg( 'ow_importtsv_header' ) ); |
241 | 219 | |
| 220 | + $wgOut->addHTML( getOptionPanelForFileUpload( |
| 221 | + array( |
| 222 | + wfMsg( 'ow_importtsv_file' ) => getFileField( 'tsvfile' ), |
| 223 | + wfMsg( 'ow_importtsv_test_run' ) => getCheckBox( 'testrun', true ) |
| 224 | + ) |
| 225 | + ) ); |
242 | 226 | } |
243 | 227 | |
244 | | - SpecialPage::addPage( new SpecialImportTSV ); |
245 | 228 | } |
246 | | - |
| 229 | + |
| 230 | + |
| 231 | + /* HELPER METHODS START HERE */ |
| 232 | + |
| 233 | + function getLanguage( $columnName ) { |
| 234 | + |
| 235 | + } |
| 236 | + |
| 237 | +} |
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialConceptMapping.php |
— | — | @@ -12,194 +12,182 @@ |
13 | 13 | * @license GPLv2 or later |
14 | 14 | */ |
15 | 15 | |
16 | | -$wgExtensionFunctions[] = 'wfSpecialConceptMapping'; |
17 | | -$wgExtensionCredits['specialpage'][] = array( |
18 | | - 'name' => 'SpecialConceptMapping', |
19 | | - 'author' => 'Kim Bruning', |
20 | | -); |
| 16 | +require_once( "WikiDataAPI.php" ); |
| 17 | +require_once( "Utilities.php" ); |
| 18 | +require_once( "WikiDataGlobals.php" ); |
21 | 19 | |
22 | | -function wfSpecialConceptMapping() { |
23 | | - require_once( "Wikidata.php" ); |
24 | | - require_once( "WikiDataAPI.php" ); |
25 | | - require_once( "Utilities.php" ); |
26 | | - require_once( "DefinedMeaningModel.php" ); |
27 | | - require_once( "WikiDataGlobals.php" ); |
28 | | - class SpecialConceptMapping extends SpecialPage { |
| 20 | +class SpecialConceptMapping extends SpecialPage { |
29 | 21 | |
30 | | - function SpecialConceptMapping() { |
31 | | - parent::__construct( 'ConceptMapping' ); |
| 22 | + function __construct() { |
| 23 | + parent::__construct( 'ConceptMapping' ); |
| 24 | + } |
| 25 | + |
| 26 | + function execute( $par ) { |
| 27 | + global $wgOut, $wgRequest, $wgUser, $wdTermDBDataSet; |
| 28 | + $wgOut->setPageTitle( wfMsg( 'ow_conceptmapping_title' ) ); |
| 29 | + |
| 30 | + if ( !$wgUser->isAllowed( 'editwikidata-' . $wdTermDBDataSet ) ) { |
| 31 | + $wgOut->addHTML( wfMsgSc( "Permission_denied" ) ); |
| 32 | + return false; |
32 | 33 | } |
| 34 | + $action = $wgRequest->getText( 'action' ); |
| 35 | + if ( !$action ) { |
| 36 | + $this->ui(); |
| 37 | + } elseif ( $action == "insert" ) { |
| 38 | + $this->insert(); |
| 39 | + } elseif ( $action == "get" ) { |
| 40 | + $this->get(); |
| 41 | + } elseif ( $action == "list_sets" ) { |
| 42 | + $this->list_sets(); |
| 43 | + } elseif ( $action == "help" ) { |
| 44 | + $this->help(); |
| 45 | + } elseif ( $action == "get_associated" ) { |
| 46 | + $this->get_associated(); |
| 47 | + } else { |
| 48 | + $wgOut->addWikiText( wfMsgSc( "conceptmapping_no_action_specified", $action ) ); |
| 49 | + $wgOut->addWikiText( wfMsgSc( "conceptmapping_help" ) ); |
| 50 | + } |
| 51 | + } |
33 | 52 | |
34 | | - function execute( $par ) { |
35 | | - global $wgOut, $wgRequest, $wgUser, $wdTermDBDataSet; |
36 | | - $wgOut->setPageTitle( wfMsg( 'ow_conceptmapping_title' ) ); |
| 53 | + protected function ui() { |
37 | 54 | |
38 | | - if ( !$wgUser->isAllowed( 'editwikidata-' . $wdTermDBDataSet ) ) { |
39 | | - $wgOut->addHTML( wfMsgSc( "Permission_denied" ) ); |
40 | | - return false; |
41 | | - } |
42 | | - $action = $wgRequest->getText( 'action' ); |
43 | | - if ( !$action ) { |
44 | | - $this->ui(); |
45 | | - } elseif ( $action == "insert" ) { |
46 | | - $this->insert(); |
47 | | - } elseif ( $action == "get" ) { |
48 | | - $this->get(); |
49 | | - } elseif ( $action == "list_sets" ) { |
50 | | - $this->list_sets(); |
51 | | - } elseif ( $action == "help" ) { |
52 | | - $this->help(); |
53 | | - } elseif ( $action == "get_associated" ) { |
54 | | - $this->get_associated(); |
| 55 | + global $wgOut, $wgRequest, $wgLang, $wgDefinedMeaning; |
| 56 | + $lang = $wgLang->getCode(); |
| 57 | + require_once( "forms.php" ); |
| 58 | + $wgOut->addHTML( wfMsgSc( "conceptmapping_uitext" ) ); |
| 59 | + $sets = wdGetDataSets(); |
| 60 | + $options = array(); |
| 61 | + $html = ""; |
| 62 | + $mappings = array(); |
| 63 | + $rq = array(); |
| 64 | + |
| 65 | + foreach ( $sets as $key => $setObject ) { |
| 66 | + $set = $setObject->getPrefix(); |
| 67 | + $rq[$set] = $wgRequest->getText( "set_" . $set ); |
| 68 | + $rq[$set] = trim( $rq[$set] ); |
| 69 | + $rq[$set] = (int)$rq[$set]; |
| 70 | + if ( $rq[$set] ) { |
| 71 | + $dmModel = new DefinedMeaningModel( $rq[$set], null, $setObject ); |
| 72 | + $defaultSel = $dmModel->getSyntransByLanguageCode( $lang ); |
| 73 | + $options[$setObject->fetchName()] = getSuggest( "set_$set", $wgDefinedMeaning, array(), $rq[$set], $defaultSel, array( 0 ), $setObject ); |
55 | 74 | } else { |
56 | | - $wgOut->addWikiText( wfMsgSc( "conceptmapping_no_action_specified", $action ) ); |
57 | | - $wgOut->addWikiText( wfMsgSc( "conceptmapping_help" ) ); |
| 75 | + $options[$setObject->fetchName()] = getSuggest( "set_$set", $wgDefinedMeaning, array(), null, null, array( 0 ), $setObject ); |
58 | 76 | } |
| 77 | + |
59 | 78 | } |
| 79 | + $wgOut->addHTML( getOptionPanel( $options ) ); |
| 80 | + $noerror = $wgRequest->getText( "suppressWarnings" ); |
60 | 81 | |
61 | | - protected function ui() { |
62 | | - |
63 | | - global $wgOut, $wgRequest, $wgLang, $wgDefinedMeaning; |
64 | | - $lang = $wgLang->getCode(); |
65 | | - require_once( "forms.php" ); |
66 | | - $wgOut->addHTML( wfMsgSc( "conceptmapping_uitext" ) ); |
67 | | - $sets = wdGetDataSets(); |
68 | | - $options = array(); |
69 | | - $html = ""; |
70 | | - $mappings = array(); |
71 | | - $rq = array(); |
72 | | - |
73 | | - foreach ( $sets as $key => $setObject ) { |
74 | | - $set = $setObject->getPrefix(); |
75 | | - $rq[$set] = $wgRequest->getText( "set_" . $set ); |
76 | | - $rq[$set] = trim( $rq[$set] ); |
77 | | - $rq[$set] = (int)$rq[$set]; |
78 | | - if ( $rq[$set] ) { |
79 | | - $dmModel = new DefinedMeaningModel( $rq[$set], null, $setObject ); |
80 | | - $defaultSel = $dmModel->getSyntransByLanguageCode( $lang ); |
81 | | - $options[$setObject->fetchName()] = getSuggest( "set_$set", $wgDefinedMeaning, array(), $rq[$set], $defaultSel, array( 0 ), $setObject ); |
| 82 | + foreach ( $sets as $key => $setObject ) { |
| 83 | + $set = $setObject->getPrefix(); |
| 84 | + if ( !$rq[$set] ) { |
| 85 | + $wgOut->addHTML( ' <span style="color:yellow">[' . wfMsgSc( "dm_not_present" ) . ']</span>' ); |
| 86 | + } else { |
| 87 | + $dmModel = new DefinedMeaningModel( $rq[$set], null, $setObject ); |
| 88 | + $dmModel->checkExistence(); |
| 89 | + if ( $dmModel->exists() ) { |
| 90 | + $id = $dmModel->getId(); |
| 91 | + $title = $dmModel->getTitleText(); |
82 | 92 | } else { |
83 | | - $options[$setObject->fetchName()] = getSuggest( "set_$set", $wgDefinedMeaning, array(), null, null, array( 0 ), $setObject ); |
| 93 | + $id = null; |
| 94 | + $title = null; |
84 | 95 | } |
85 | | - |
86 | | - } |
87 | | - $wgOut->addHTML( getOptionPanel( $options ) ); |
88 | | - $noerror = $wgRequest->getText( "suppressWarnings" ); |
89 | | - |
90 | | - foreach ( $sets as $key => $setObject ) { |
91 | | - $set = $setObject->getPrefix(); |
92 | | - if ( !$rq[$set] ) { |
93 | | - $wgOut->addHTML( ' <span style="color:yellow">[' . wfMsgSc( "dm_not_present" ) . ']</span>' ); |
94 | | - } else { |
95 | | - $dmModel = new DefinedMeaningModel( $rq[$set], null, $setObject ); |
96 | | - $dmModel->checkExistence(); |
97 | | - if ( $dmModel->exists() ) { |
98 | | - $id = $dmModel->getId(); |
99 | | - $title = $dmModel->getTitleText(); |
100 | | - } else { |
101 | | - $id = null; |
102 | | - $title = null; |
| 96 | + if ( !$noerror ) { |
| 97 | + $wgOut->addHTML( "$key: " . $rq[$set] . " ($title)" ); |
| 98 | + } |
| 99 | + if ( $id != null ) { |
| 100 | + $mappings[$key] = $id; |
| 101 | + if ( !$noerror ) { |
| 102 | + $wgOut->addHTML( ' <span style="color:green">[' . wfMsgSc( "dm_OK" ) . ']</span>' ); |
103 | 103 | } |
| 104 | + } else { |
104 | 105 | if ( !$noerror ) { |
105 | | - $wgOut->addHTML( "$key: " . $rq[$set] . " ($title)" ); |
| 106 | + $wgOut->addHTML( ' <span style="color:red">[' . wfMsgSc( "dm_not_found" ) . ']</span>' ); |
106 | 107 | } |
107 | | - if ( $id != null ) { |
108 | | - $mappings[$key] = $id; |
109 | | - if ( !$noerror ) { |
110 | | - $wgOut->addHTML( ' <span style="color:green">[' . wfMsgSc( "dm_OK" ) . ']</span>' ); |
111 | | - } |
112 | | - } else { |
113 | | - if ( !$noerror ) { |
114 | | - $wgOut->addHTML( ' <span style="color:red">[' . wfMsgSc( "dm_not_found" ) . ']</span>' ); |
115 | | - } |
116 | | - } |
117 | 108 | } |
118 | | - $wgOut->addHTML( "<br />\n" ); |
119 | 109 | } |
120 | | - if ( sizeOf( $mappings ) > 1 ) { |
121 | | - createConceptMapping( $mappings ); |
122 | | - $wgOut->addHTML( wfMsgSc( "mapping_successful" ) ); |
123 | | - } else { |
124 | | - $wgOut->addHTML( wfMsgSc( "mapping_unsuccessful" ) ); |
125 | | - } |
126 | | - |
| 110 | + $wgOut->addHTML( "<br />\n" ); |
127 | 111 | } |
128 | | - |
129 | | - protected function getDm( $dataset ) { |
130 | | - global $wgRequest; |
131 | | - $setname = "set_" . $dataset->getPrefix(); |
132 | | - $rq = $wgRequest->getText( $setname ); |
133 | | - $html = getTextBox( $setname, $rq ); |
134 | | - return $html; |
| 112 | + if ( sizeOf( $mappings ) > 1 ) { |
| 113 | + createConceptMapping( $mappings ); |
| 114 | + $wgOut->addHTML( wfMsgSc( "mapping_successful" ) ); |
| 115 | + } else { |
| 116 | + $wgOut->addHTML( wfMsgSc( "mapping_unsuccessful" ) ); |
135 | 117 | } |
136 | 118 | |
| 119 | + } |
| 120 | + |
| 121 | + protected function getDm( $dataset ) { |
| 122 | + global $wgRequest; |
| 123 | + $setname = "set_" . $dataset->getPrefix(); |
| 124 | + $rq = $wgRequest->getText( $setname ); |
| 125 | + $html = getTextBox( $setname, $rq ); |
| 126 | + return $html; |
| 127 | + } |
| 128 | + |
| 129 | + |
| 130 | + protected function help() { |
| 131 | + global $wgOut; |
| 132 | + $wgOut->addWikiText( "<h2>Help</h2>" ); |
| 133 | + $wgOut->addWikiText( wfMsgSc( "conceptmapping_help" ) ); |
| 134 | + } |
| 135 | + |
| 136 | + protected function insert() { |
| 137 | + global |
| 138 | + $wgRequest, $wgOut; |
137 | 139 | |
138 | | - protected function help() { |
139 | | - global $wgOut; |
140 | | - $wgOut->addWikiText( "<h2>Help</h2>" ); |
141 | | - $wgOut->addWikiText( wfMsgSc( "conceptmapping_help" ) ); |
142 | | - } |
143 | | - |
144 | | - protected function insert() { |
145 | | - global |
146 | | - $wgRequest, $wgOut; |
147 | | - |
148 | | - # $wgRequest->getText( 'page' ); |
149 | | - $sets = wdGetDataSets(); |
150 | | - # $requests=$wgRequest->getValues(); |
151 | | - $wgOut->addWikiText( "<h2>" . wfMsgSc( "will_insert" ) . "</h2>" ); |
152 | | - $map = array(); |
153 | | - foreach ( $sets as $key => $set ) { |
154 | | - $dc = $set->getPrefix(); |
155 | | - $dm_id = $wgRequest->getText( $dc ); |
156 | | - $name = $set->fetchName(); |
| 140 | + # $wgRequest->getText( 'page' ); |
| 141 | + $sets = wdGetDataSets(); |
| 142 | + # $requests=$wgRequest->getValues(); |
| 143 | + $wgOut->addWikiText( "<h2>" . wfMsgSc( "will_insert" ) . "</h2>" ); |
| 144 | + $map = array(); |
| 145 | + foreach ( $sets as $key => $set ) { |
| 146 | + $dc = $set->getPrefix(); |
| 147 | + $dm_id = $wgRequest->getText( $dc ); |
| 148 | + $name = $set->fetchName(); |
157 | 149 | |
158 | | - $dm_id_ui = $dm_id; # Only for teh purdy |
159 | | - if ( $dm_id_ui == null ) |
160 | | - $dm_id_ui = "unset"; |
161 | | - $wgOut->addWikiText( "$name ->$dm_id_ui" ); |
162 | | - $map[$dc] = $dm_id; |
163 | | - # $dbr=&wfGetDB(DB_MASTER); |
164 | | - } |
165 | | - createConceptMapping( $map ); |
| 150 | + $dm_id_ui = $dm_id; # Only for teh purdy |
| 151 | + if ( $dm_id_ui == null ) |
| 152 | + $dm_id_ui = "unset"; |
| 153 | + $wgOut->addWikiText( "$name ->$dm_id_ui" ); |
| 154 | + $map[$dc] = $dm_id; |
| 155 | + # $dbr=&wfGetDB(DB_MASTER); |
166 | 156 | } |
| 157 | + createConceptMapping( $map ); |
| 158 | + } |
167 | 159 | |
168 | | - protected function get() { |
169 | | - global |
170 | | - $wgOut, $wgRequest; |
171 | | - $concept_id = $wgRequest->getText( "concept" ); |
172 | | - $wgOut->addWikiText( "<h2>" . wfMsgSc( "contents_of_mapping" ) . "</h2>" ); |
173 | | - $map = readConceptMapping( $concept_id ); |
174 | | - # $sets=wdGetDataSets(); |
| 160 | + protected function get() { |
| 161 | + global |
| 162 | + $wgOut, $wgRequest; |
| 163 | + $concept_id = $wgRequest->getText( "concept" ); |
| 164 | + $wgOut->addWikiText( "<h2>" . wfMsgSc( "contents_of_mapping" ) . "</h2>" ); |
| 165 | + $map = readConceptMapping( $concept_id ); |
| 166 | + # $sets=wdGetDataSets(); |
175 | 167 | |
176 | | - foreach ( $map as $dc => $dm_id ) { |
177 | | - $wgOut->addWikiText( "$dc -> $dm_id" ); |
178 | | - } |
| 168 | + foreach ( $map as $dc => $dm_id ) { |
| 169 | + $wgOut->addWikiText( "$dc -> $dm_id" ); |
179 | 170 | } |
| 171 | + } |
180 | 172 | |
181 | | - protected function list_sets() { |
182 | | - global $wgOut; |
183 | | - $wgOut->addWikiText( "<h2>" . wfMsgSc( "available contexts" ) . "</h2>" ); |
184 | | - $sets = wdGetDataSets(); |
185 | | - foreach ( $sets as $key => $set ) { |
186 | | - $name = $set->fetchName(); |
187 | | - $wgOut->addWikiText( "$key => $name" ); |
188 | | - } |
| 173 | + protected function list_sets() { |
| 174 | + global $wgOut; |
| 175 | + $wgOut->addWikiText( "<h2>" . wfMsgSc( "available contexts" ) . "</h2>" ); |
| 176 | + $sets = wdGetDataSets(); |
| 177 | + foreach ( $sets as $key => $set ) { |
| 178 | + $name = $set->fetchName(); |
| 179 | + $wgOut->addWikiText( "$key => $name" ); |
189 | 180 | } |
| 181 | + } |
190 | 182 | |
191 | | - protected function get_associated() { |
192 | | - global $wgOut, $wgRequest; |
193 | | - $dm_id = $wgRequest->getText( "dm" ); |
194 | | - $dc = $wgRequest->getText( "dc" ); |
195 | | - $map = getAssociatedByConcept( $dm_id, $dc ); |
196 | | - foreach ( $map as $dc => $dm_id ) { |
197 | | - $wgOut->addWikiText( "$dc -> $dm_id" ); |
198 | | - } |
| 183 | + protected function get_associated() { |
| 184 | + global $wgOut, $wgRequest; |
| 185 | + $dm_id = $wgRequest->getText( "dm" ); |
| 186 | + $dc = $wgRequest->getText( "dc" ); |
| 187 | + $map = getAssociatedByConcept( $dm_id, $dc ); |
| 188 | + foreach ( $map as $dc => $dm_id ) { |
| 189 | + $wgOut->addWikiText( "$dc -> $dm_id" ); |
199 | 190 | } |
200 | | - |
201 | 191 | } |
202 | 192 | |
203 | | - SpecialPage::addPage( new SpecialConceptMapping ); |
204 | | - |
205 | 193 | } |
206 | 194 | |
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialCopy.php |
— | — | @@ -17,160 +17,149 @@ |
18 | 18 | * @license GPLv2 or later. |
19 | 19 | */ |
20 | 20 | |
21 | | -$wgExtensionFunctions[] = 'wfSpecialCopy'; |
22 | | -$wgExtensionCredits['specialpage'][] = array( |
23 | | - 'name' => 'SpecialCopy', |
24 | | - 'author' => 'Alan Smithee', |
25 | | -); |
| 21 | +require_once( "WikiDataAPI.php" ); |
| 22 | +require_once( "Utilities.php" ); |
| 23 | +require_once( "Copy.php" ); |
26 | 24 | |
27 | | -function wfSpecialCopy() { |
28 | | - require_once( "Wikidata.php" ); |
29 | | - require_once( "WikiDataAPI.php" ); |
30 | | - require_once( "Utilities.php" ); |
31 | | - require_once( "DefinedMeaningModel.php" ); |
32 | | - require_once( "Copy.php" ); |
33 | | - class SpecialCopy extends UnlistedSpecialPage { |
| 25 | +class SpecialCopy extends UnlistedSpecialPage { |
34 | 26 | |
35 | | - function __construct() { |
36 | | - parent::__construct( 'Copy' ); |
37 | | - } |
38 | | - function execute( $par ) { |
39 | | - global $wgOut, $wgRequest, $wgUser, $wdTermDBDataSet; |
| 27 | + function __construct() { |
| 28 | + parent::__construct( 'Copy' ); |
| 29 | + } |
| 30 | + |
| 31 | + function execute( $par ) { |
| 32 | + global $wgOut, $wgRequest, $wgUser, $wdTermDBDataSet; |
40 | 33 | |
41 | | - # $wgOut->setPageTitle("Special:Copy"); |
42 | | - if ( !$wgUser->isAllowed( 'wikidata-copy' ) ) { |
| 34 | + # $wgOut->setPageTitle("Special:Copy"); |
| 35 | + if ( !$wgUser->isAllowed( 'wikidata-copy' ) ) { |
43 | 36 | |
44 | | - $wgOut->addHTML( wfMsgSc( "Permission_denied" ) ); |
45 | | - return false; |
46 | | - } |
| 37 | + $wgOut->addHTML( wfMsgSc( "Permission_denied" ) ); |
| 38 | + return false; |
| 39 | + } |
47 | 40 | |
48 | | - $action = $wgRequest->getText( 'action' ); |
49 | | - if ( !$action ) { |
50 | | - $this->ui(); |
51 | | - } elseif ( $action == "copy" ) { |
52 | | - $this->copy_by_param(); |
53 | | - } elseif ( $action == "list" ) { |
54 | | - $this->list_sets(); |
55 | | - } elseif ( $action == "help" ) { |
56 | | - $this->help(); |
57 | | - } else { |
58 | | - $wgOut->addWikiText( wfMsgSc( "no_action_specified", $action ) ); |
59 | | - $wgOut->addWikiText( wfMsgSc( "copy_help" ) ); |
60 | | - } |
| 41 | + $action = $wgRequest->getText( 'action' ); |
| 42 | + if ( !$action ) { |
| 43 | + $this->ui(); |
| 44 | + } elseif ( $action == "copy" ) { |
| 45 | + $this->copy_by_param(); |
| 46 | + } elseif ( $action == "list" ) { |
| 47 | + $this->list_sets(); |
| 48 | + } elseif ( $action == "help" ) { |
| 49 | + $this->help(); |
| 50 | + } else { |
| 51 | + $wgOut->addWikiText( wfMsgSc( "no_action_specified", $action ) ); |
| 52 | + $wgOut->addWikiText( wfMsgSc( "copy_help" ) ); |
61 | 53 | } |
| 54 | + } |
62 | 55 | |
63 | | - /** reserved for ui elements */ |
64 | | - protected function ui() { |
| 56 | + /** reserved for ui elements */ |
| 57 | + protected function ui() { |
65 | 58 | |
66 | | - global $wgOut ; |
67 | | - $wgOut->addWikiText( wfMsgSc( "no_action_specified" ) ); |
| 59 | + global $wgOut ; |
| 60 | + $wgOut->addWikiText( wfMsgSc( "no_action_specified" ) ); |
68 | 61 | |
69 | | - } |
| 62 | + } |
70 | 63 | |
71 | | - /** display a helpful help message. |
72 | | - * (if desired) |
73 | | - */ |
74 | | - protected function help() { |
75 | | - global $wgOut; |
76 | | - $wgOut->addWikiText( "<h2>Help</h2>" ); |
77 | | - $wgOut->addWikiText( wfMsgSc( "copy_help" ) ); |
78 | | - } |
| 64 | + /** display a helpful help message. |
| 65 | + * (if desired) |
| 66 | + */ |
| 67 | + protected function help() { |
| 68 | + global $wgOut; |
| 69 | + $wgOut->addWikiText( "<h2>Help</h2>" ); |
| 70 | + $wgOut->addWikiText( wfMsgSc( "copy_help" ) ); |
| 71 | + } |
| 72 | + |
| 73 | + /**read in and partially validate parameters, |
| 74 | + * then call _doCopy() |
| 75 | + */ |
| 76 | + protected function copy_by_param() { |
| 77 | + global |
| 78 | + $wgRequest, $wgOut; |
79 | 79 | |
80 | | - /**read in and partially validate parameters, |
81 | | - * then call _doCopy() |
82 | | - */ |
83 | | - protected function copy_by_param() { |
84 | | - global |
85 | | - $wgRequest, $wgOut; |
86 | | - |
87 | | - $dmid_dirty = $wgRequest->getText( "dmid" ); |
88 | | - $dc1_dirty = $wgRequest->getText( "dc1" ); |
89 | | - $dc2_dirty = $wgRequest->getText( "dc2" ); |
| 80 | + $dmid_dirty = $wgRequest->getText( "dmid" ); |
| 81 | + $dc1_dirty = $wgRequest->getText( "dc1" ); |
| 82 | + $dc2_dirty = $wgRequest->getText( "dc2" ); |
90 | 83 | |
91 | | - $abort = false; # check all input before aborting |
| 84 | + $abort = false; # check all input before aborting |
92 | 85 | |
93 | | - if ( is_null( $dmid_dirty ) ) { |
94 | | - $wgOut->addWikiText( wfMsgSc( "please_provide_dmid" ) ); |
95 | | - $abort = true; |
96 | | - } |
97 | | - if ( is_null( $dc1_dirty ) ) { |
98 | | - $wgOut->addWikiText( wfMsgSc( "please_provide_dc1" ) ); |
99 | | - $abort = true; |
100 | | - } |
101 | | - if ( is_null( $dc2_dirty ) ) { |
102 | | - $wgOut->addWikiText( wfMsgSc( "please_provide_dc2" ) ); |
103 | | - $abort = true; |
104 | | - } |
| 86 | + if ( is_null( $dmid_dirty ) ) { |
| 87 | + $wgOut->addWikiText( wfMsgSc( "please_provide_dmid" ) ); |
| 88 | + $abort = true; |
| 89 | + } |
| 90 | + if ( is_null( $dc1_dirty ) ) { |
| 91 | + $wgOut->addWikiText( wfMsgSc( "please_provide_dc1" ) ); |
| 92 | + $abort = true; |
| 93 | + } |
| 94 | + if ( is_null( $dc2_dirty ) ) { |
| 95 | + $wgOut->addWikiText( wfMsgSc( "please_provide_dc2" ) ); |
| 96 | + $abort = true; |
| 97 | + } |
105 | 98 | |
106 | | - if ( $abort ) |
107 | | - return; |
| 99 | + if ( $abort ) |
| 100 | + return; |
108 | 101 | |
109 | | - # seems ok so far, let's try and copy. |
110 | | - $success = $this->_doCopy( $dmid_dirty, $dc1_dirty, $dc2_dirty ); |
111 | | - if ( $success ) |
112 | | - $this->autoredir(); |
113 | | - else |
114 | | - $wgOut->addWikiText( wfMsgSc( "copy_unsuccessful" ) ); |
115 | | - } |
| 102 | + # seems ok so far, let's try and copy. |
| 103 | + $success = $this->_doCopy( $dmid_dirty, $dc1_dirty, $dc2_dirty ); |
| 104 | + if ( $success ) |
| 105 | + $this->autoredir(); |
| 106 | + else |
| 107 | + $wgOut->addWikiText( wfMsgSc( "copy_unsuccessful" ) ); |
| 108 | + } |
116 | 109 | |
117 | | - /** automatically redirects to another page. |
118 | | - * make sure you haven't used $wgOut before calling this! |
119 | | - */ |
120 | | - protected function autoredir() { |
121 | | - global $wgOut, $wgRequest; |
| 110 | + /** automatically redirects to another page. |
| 111 | + * make sure you haven't used $wgOut before calling this! |
| 112 | + */ |
| 113 | + protected function autoredir() { |
| 114 | + global $wgOut, $wgRequest; |
122 | 115 | |
123 | | - $dmid_dirty = $wgRequest->getText( "dmid" ); |
124 | | - $dc1_dirty = $wgRequest->getText( "dc1" ); |
125 | | - $dc2_dirty = $wgRequest->getText( "dc2" ); |
| 116 | + $dmid_dirty = $wgRequest->getText( "dmid" ); |
| 117 | + $dc1_dirty = $wgRequest->getText( "dc1" ); |
| 118 | + $dc2_dirty = $wgRequest->getText( "dc2" ); |
126 | 119 | |
127 | | - # Where should we redirect to? |
128 | | - $meanings = getDefinedMeaningDataAssociatedByConcept( $dmid_dirty, $dc1_dirty ); |
129 | | - $targetdmm = $meanings[$dc2_dirty]; |
130 | | - $title = $targetdmm->getTitleObject(); |
131 | | - $url = $title->getLocalURL( "dataset=$dc2_dirty&action=edit" ); |
| 120 | + # Where should we redirect to? |
| 121 | + $meanings = getDefinedMeaningDataAssociatedByConcept( $dmid_dirty, $dc1_dirty ); |
| 122 | + $targetdmm = $meanings[$dc2_dirty]; |
| 123 | + $title = $targetdmm->getTitleObject(); |
| 124 | + $url = $title->getLocalURL( "dataset=$dc2_dirty&action=edit" ); |
132 | 125 | |
133 | | - # do the redirect |
134 | | - $wgOut->disable(); |
135 | | - header( 'Location: ' . $url ); |
136 | | - # $wgOut->addHTML("<a href=\"$url\">$url</a>"); |
137 | | - } |
| 126 | + # do the redirect |
| 127 | + $wgOut->disable(); |
| 128 | + header( 'Location: ' . $url ); |
| 129 | + # $wgOut->addHTML("<a href=\"$url\">$url</a>"); |
| 130 | + } |
138 | 131 | |
139 | 132 | |
140 | | - /* Using Copy.php; perform a copy of a defined meaning from one dataset to another, |
141 | | - provided the user has permission to do so,*/ |
142 | | - protected function _doCopy( $dmid_dirty, $dc1_dirty, $dc2_dirty ) { |
143 | | - global |
144 | | - $wgCommunityEditPermission, $wgOut, $wgUser, $wgCommunity_dc; |
145 | | - |
146 | | - # escape parameters |
147 | | - $dmid = mysql_real_escape_string( $dmid_dirty ); |
148 | | - $dc1 = mysql_real_escape_string( $dc1_dirty ); |
149 | | - $dc2 = mysql_real_escape_string( $dc2_dirty ); |
| 133 | + /* Using Copy.php; perform a copy of a defined meaning from one dataset to another, |
| 134 | + provided the user has permission to do so,*/ |
| 135 | + protected function _doCopy( $dmid_dirty, $dc1_dirty, $dc2_dirty ) { |
| 136 | + global |
| 137 | + $wgCommunityEditPermission, $wgOut, $wgUser, $wgCommunity_dc; |
| 138 | + |
| 139 | + # escape parameters |
| 140 | + $dmid = mysql_real_escape_string( $dmid_dirty ); |
| 141 | + $dc1 = mysql_real_escape_string( $dc1_dirty ); |
| 142 | + $dc2 = mysql_real_escape_string( $dc2_dirty ); |
150 | 143 | |
151 | | - # check permission |
152 | | - if ( !( $wgUser->isAllowed( 'wikidata-copy' ) ) or $dc2 != $wgCommunity_dc ) { |
153 | | - $wgOut->addHTML( wfMsgSc( "Permission_denied" ) ); |
154 | | - return false; # we didn't perform the copy. |
155 | | - } |
| 144 | + # check permission |
| 145 | + if ( !( $wgUser->isAllowed( 'wikidata-copy' ) ) or $dc2 != $wgCommunity_dc ) { |
| 146 | + $wgOut->addHTML( wfMsgSc( "Permission_denied" ) ); |
| 147 | + return false; # we didn't perform the copy. |
| 148 | + } |
156 | 149 | |
157 | | - # copy |
158 | | - CopyTools::newCopyTransaction( $dc1, $dc2 ); |
159 | | - $dmc = new DefinedMeaningCopier( $dmid, $dc1, $dc2 ); |
160 | | - $dmc->dup(); |
| 150 | + # copy |
| 151 | + CopyTools::newCopyTransaction( $dc1, $dc2 ); |
| 152 | + $dmc = new DefinedMeaningCopier( $dmid, $dc1, $dc2 ); |
| 153 | + $dmc->dup(); |
161 | 154 | |
162 | | - # For purposes of current "edit copy", |
163 | | - # having the dm be already_there() is ok. |
164 | | - # (hence commented out) |
165 | | - # if ($dmc->already_there() ) { |
166 | | - # $wgOut->addHTML(wfMsgSc("already_there")); |
167 | | - # return false; |
168 | | - # } |
| 155 | + # For purposes of current "edit copy", |
| 156 | + # having the dm be already_there() is ok. |
| 157 | + # (hence commented out) |
| 158 | + # if ($dmc->already_there() ) { |
| 159 | + # $wgOut->addHTML(wfMsgSc("already_there")); |
| 160 | + # return false; |
| 161 | + # } |
169 | 162 | |
170 | | - return true; # seems everything went ok. |
| 163 | + return true; # seems everything went ok. |
171 | 164 | |
172 | | - } |
173 | 165 | } |
174 | | - SpecialPage::addPage( new SpecialCopy ); |
175 | | - |
176 | 166 | } |
177 | | - |