r65538 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65537‎ | r65538 | r65539 >
Date:04:21, 26 April 2010
Author:tisane
Status:deferred (Comments)
Tags:
Comment:
Internationalizing Wikipedia URLs, adding API functionality to insert/delete page titles from rped_page, etc.
Modified paths:
  • /trunk/extensions/RPED/ApiRPED.php (added) (history)
  • /trunk/extensions/RPED/RPED.hooks.php (modified) (history)
  • /trunk/extensions/RPED/RPED.i18n.php (modified) (history)
  • /trunk/extensions/RPED/RPED.php (modified) (history)

Diff [purge]

Index: trunk/extensions/RPED/RPED.php
@@ -27,7 +27,6 @@
2828 }
2929
3030 $wgExtensionCredits['other'][] = array(
31 - 'path' => __FILE__,
3231 'name' => 'Remote Page Existence Detection',
3332 'author' => 'Tisane',
3433 'url' => 'http://www.mediawiki.org/wiki/Extension:RemotePageExistenceDetection',
@@ -38,6 +37,9 @@
3938 $dir = dirname( __FILE__ ) . '/';
4039 $wgAutoloadClasses['RPEDHooks'] = $dir . 'RPED.hooks.php';
4140 $wgExtensionMessagesFiles['RPED'] = $dir . 'RPED.i18n.php';
 41+$wgAutoloadClasses['ApiRPED'] = $dir.'ApiRPED.php';
 42+$wgAPIModules['rped'] = 'ApiRPED';
 43+$wgGroupPermissions['RPED']['rped'] = true;
4244
4345 $wgHooks['LoadExtensionSchemaUpdates'][] = 'RPEDHooks::RPEDCreateTable';
4446 $wgHooks['LinkBegin'][] = 'RPEDHooks::wikipediaLink';
Index: trunk/extensions/RPED/RPED.hooks.php
@@ -22,7 +22,7 @@
2323 &$customAttribs, &$query, &$options, &$ret
2424 ) {
2525 global $wgLocalStyle, $wgRemoteStyle, $wgPureWikiDeletionInEffect, $wgTitle, $wgRequest;
26 -
 26+ wfLoadExtensionMessages('RPED');
2727 if ( $wgTitle->getNamespace () == -1 ) {
2828 return true;
2929 }
@@ -86,8 +86,7 @@
8787 return true;
8888 } else {
8989 $title = htmlentities( $title );
90 - // FIXME: make language configurable, or the same as content language.
91 - $url = 'http://en.wikipedia.org/wiki/' . $title;
 90+ $url = wfMsgExt( 'rped-wikipedia-url','parsemag') . $title;
9291
9392 // The page that we'll link to
9493 $text = '<a href="' . $url . '">' . $text . '</a>';
Index: trunk/extensions/RPED/ApiRPED.php
@@ -0,0 +1,105 @@
 2+<?php
 3+if (!defined('MEDIAWIKI')) {
 4+ die();
 5+}
 6+
 7+class ApiRPED extends ApiBase {
 8+ public function __construct($main, $action) {
 9+ parent :: __construct($main, $action);
 10+ }
 11+ public function execute() {
 12+ global $wgUser;
 13+ /*if (!$this->userCanExecute( $wgUser )) {
 14+ $this->displayRestrictionError();
 15+ return;
 16+ }*/
 17+
 18+ if (!$wgUser->isAllowed( 'rped' ) ){
 19+ $this->displayRestrictionError();
 20+ return;
 21+ }
 22+
 23+
 24+ #$dbw->insert('rped_pages',array('rped_page_title' => $subValue));
 25+ $params = $this->extractRequestParams(false);
 26+ /*foreach ($params as $key => $value) {
 27+ $dbw->insert('rped_page',array('rped_page_title' => $key));
 28+ $dbw->insert('rped_page',array('rped_page_title' => $value));
 29+ }*/
 30+ foreach ($params as $key => $value) {
 31+ if ($key!=null && $value!=null){
 32+ ApiRPED::paramProcess($key,$value);
 33+ }
 34+
 35+ }
 36+ return;
 37+ }
 38+
 39+ public function paramProcess($key,$value){
 40+ $dbr = wfGetDB( DB_SLAVE );
 41+ $dbw = wfGetDB( DB_MASTER );
 42+ $myInputNum=0;
 43+ for ($count=0; $count<strlen($value); $count++){
 44+ if (substr($value,$count,1)=='|'){
 45+ $myInputNum++;
 46+ } else {
 47+ if (!isset($myInput[$myInputNum])){
 48+ $myInput[$myInputNum]='';
 49+ }
 50+ if (substr($value,$count,1)==' '){
 51+ $myInput[$myInputNum].='_';
 52+ } else {
 53+ $myInput[$myInputNum].=substr($value,$count,1);
 54+ }
 55+ }
 56+ }
 57+ if (isset($myInput)){
 58+ foreach ($myInput as $subValue){
 59+
 60+ if (isset($subValue) && !($subValue===null)){
 61+ $existCheck=null;
 62+ $existCheck=$dbr->selectrow('rped_page','rped_page_title',array
 63+ ('rped_page_title' => $subValue));
 64+ #$dbw->insert('rped_page',array('rped_page_title' => "key: ".$key));
 65+ #$dbw->insert('rped_page',array('rped_page_title' => "subValue: ".$subValue));
 66+ #if($key=='insert' && !isset($existCheck) && $existCheck!=null){
 67+ if($key=='insert' && (!isset($existCheck) || $existCheck==null)){
 68+ $dbw->insert('rped_page',array('rped_page_title' => $subValue));
 69+ }
 70+ if ($key=='delete' && isset($existCheck) && $existCheck!=null){
 71+ $dbw->delete('rped_page',array('rped_page_title' => $subValue));
 72+ }
 73+ }
 74+ }
 75+ }
 76+ }
 77+
 78+ public function getAllowedParams(){
 79+ return array(
 80+ 'insert' => null,
 81+ 'delete' => null
 82+ );
 83+ }
 84+
 85+ public function getParamDescription(){
 86+ return array (
 87+ 'insert' => 'page name to insert',
 88+ 'delete' => 'page name to delete'
 89+ );
 90+ }
 91+
 92+ public function getDescription(){
 93+ return array (
 94+ 'This module is used to insert data into, and delete date from, ',
 95+ 'the RPED page name table.'
 96+ );
 97+ }
 98+
 99+ public function getVersion() {
 100+ return __CLASS__ . ': $Id$';
 101+ }
 102+
 103+ public function displayRestrictionError(){
 104+ echo("Access denied.");
 105+ }
 106+}
\ No newline at end of file
Property changes on: trunk/extensions/RPED/ApiRPED.php
___________________________________________________________________
Added: svn:eol-style
1107 + native
Index: trunk/extensions/RPED/RPED.i18n.php
@@ -12,6 +12,7 @@
1313 $messages['en'] = array(
1414 'rped' => 'Remote page existence detection',
1515 'rped-desc' => 'Links wikilinks to Wikipedia if the page does not exist on the local wiki but exists on Wikipedia',
 16+ 'rped-wikipedia-url' => 'http://en.wikipedia.org/wiki/',
1617 );
1718
1819 /** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца))
@@ -21,6 +22,7 @@
2223 $messages['be-tarask'] = array(
2324 'rped' => 'Выяўленьне існаваньня вонкавай старонкі',
2425 'rped-desc' => 'Устаўляе вікі-спасылкі на Вікіпэдыю, калі старонка не існуе ў лякальнай вікі, але існуе ў Вікіпэдыі',
 26+ 'rped-wikipedia-url' => 'http://be.wikipedia.org/',
2527 );
2628
2729 /** German (Deutsch)
@@ -29,6 +31,7 @@
3032 $messages['de'] = array(
3133 'rped' => 'Ermittlung websitefremder Webseiten',
3234 'rped-desc' => 'Leitet Wikilinks zur Wikipedia, sofern die betreffende Seite nicht im lokalen Wiki, aber in der Wikipedia vorhanden ist',
 35+ 'rped-wikipedia-url' => 'http://de.wikipedia.org/',
3336 );
3437
3538 /** Lower Sorbian (Dolnoserbski)
@@ -37,6 +40,7 @@
3841 $messages['dsb'] = array(
3942 'rped' => 'Namakanje eksistence zdalonego boka',
4043 'rped-desc' => 'Wótkazujo wikiwótkaze do Wikipedije, jolic bok njeeksistěrujo w lokalnem wikiju, ale eksistěrujo we Wikipediji',
 44+ 'rped-wikipedia-url' => 'http://dsb.wikipedia.org/',
4145 );
4246
4347 /** Spanish (Español)
@@ -45,6 +49,7 @@
4650 $messages['es'] = array(
4751 'rped' => 'Detección de existencia de página remota',
4852 'rped-desc' => 'Enlaza los wikienlaces a Wikipedia si la página no existe en la wiki local pero existe en Wikipedia',
 53+ 'rped-wikipedia-url' => 'http://es.wikipedia.org/',
4954 );
5055
5156 /** French (Français)
@@ -53,6 +58,7 @@
5459 $messages['fr'] = array(
5560 'rped' => "Détection d'existence des pages à distance",
5661 'rped-desc' => "Lie les wikiliens vers Wikipédia si la page n'existe pas sur le wiki local mais existe sur Wikipédia",
 62+ 'rped-wikipedia-url' => 'http://fr.wikipedia.org/',
5763 );
5864
5965 /** Galician (Galego)
@@ -61,6 +67,7 @@
6268 $messages['gl'] = array(
6369 'rped' => 'Detección remota da existencia de páxinas',
6470 'rped-desc' => 'Crea ligazóns cara á Wikipedia se a páxina non existe no wiki local pero si na Wikipedia',
 71+ 'rped-wikipedia-url' => 'http://gl.wikipedia.org/',
6572 );
6673
6774 /** Swiss German (Alemannisch)
@@ -69,6 +76,7 @@
7077 $messages['gsw'] = array(
7178 'rped' => 'Erkännig vu främde Netzsyte',
7279 'rped-desc' => 'Leitet Wikilinks uf d Wikipedia, wänn die Syte nit im lokale Wiki git, derfir aber in dr Wikipedia',
 80+ 'rped-wikipedia-url' => 'http://gsw.wikipedia.org/',
7381 );
7482
7583 /** Upper Sorbian (Hornjoserbsce)
@@ -77,6 +85,7 @@
7886 $messages['hsb'] = array(
7987 'rped' => 'Wotkryće eksistency zdaleneje strony',
8088 'rped-desc' => 'Wotkazuje wikiwotkazy do Wikipedije, jeli strona njeeksistuje w lokalnym wikiju, ale eksistuje we Wikipediji',
 89+ 'rped-wikipedia-url' => 'http://hsb.wikipedia.org/',
8190 );
8291
8392 /** Hungarian (Magyar)
@@ -85,6 +94,7 @@
8695 $messages['hu'] = array(
8796 'rped' => 'Ellenőrzi, hogy egy távoli lap létezik-e',
8897 'rped-desc' => 'A wikilinkeket a Wikipédiára irányítja, ha a lap nem létezik a helyi wikiben, de a Wikipédián igen',
 98+ 'rped-wikipedia-url' => 'http://hu.wikipedia.org/',
8999 );
90100
91101 /** Interlingua (Interlingua)
@@ -93,6 +103,7 @@
94104 $messages['ia'] = array(
95105 'rped' => 'Detection del existentia de paginas remote',
96106 'rped-desc' => 'Face wiki-ligamines a Wikipedia si le pagina non existe in le wiki local ma existe in Wikipedia',
 107+ 'rped-wikipedia-url' => 'http://ia.wikipedia.org/',
97108 );
98109
99110 /** Macedonian (Македонски)
@@ -101,6 +112,7 @@
102113 $messages['mk'] = array(
103114 'rped' => 'Пронаоѓач на постоечка надворешна страница',
104115 'rped-desc' => 'Поврзува викиврски со Википедија ако страницата не постои на локалното вики, но постои на Википедија',
 116+ 'rped-wikipedia-url' => 'http://mk.wikipedia.org/',
105117 );
106118
107119 /** Dutch (Nederlands)
@@ -109,6 +121,7 @@
110122 $messages['nl'] = array(
111123 'rped' => "Detectie van pagina's in andere wiki's",
112124 'rped-desc' => 'Verwijst naar Wikipedia als de pagina niet bestaat in de lokale wiki maar wel in Wikipedia',
 125+ 'rped-wikipedia-url' => 'http://nl.wikipedia.org/',
113126 );
114127
115128 /** Norwegian (bokmål)‬ (‪Norsk (bokmål)‬)
@@ -117,22 +130,16 @@
118131 $messages['no'] = array(
119132 'rped' => 'Eksistensdeteksjon av eksterne sider',
120133 'rped-desc' => 'Lenker wikilenker til Wikipedia om siden ikke finnes på den lokale wikien men finnes på Wikipedia',
 134+ 'rped-wikipedia-url' => 'http://no.wikipedia.org/',
121135 );
122136
123 -/** Occitan (Occitan)
124 - * @author Cedric31
125 - */
126 -$messages['oc'] = array(
127 - 'rped' => "Deteccion d'existéncia de las paginas a distància",
128 - 'rped-desc' => 'Liga los wikiligams cap a Wikipèdia se la pagina existís pas sul wiki local mas existís sus Wikipèdia',
129 -);
130 -
131137 /** Piedmontese (Piemontèis)
132138 * @author Borichèt
133139 */
134140 $messages['pms'] = array(
135141 'rped' => "Determinassion d'esistensa dle pàgine a distansa",
136142 'rped-desc' => "A colega j'anliure wiki a Wikipedia se la pàgina a esist pa an sla wiki local ma a esist dzora a Wikipedia",
 143+ 'rped-wikipedia-url' => 'http://pms.wikipedia.org/',
137144 );
138145
139146 /** Portuguese (Português)
@@ -141,6 +148,7 @@
142149 $messages['pt'] = array(
143150 'rped' => 'Detecção da existência de páginas remotas',
144151 'rped-desc' => 'Liga um link à Wikipédia, se a página de destino não existe na wiki local mas existe na Wikipédia',
 152+ 'rped-wikipedia-url' => 'http://pt.wikipedia.org/',
145153 );
146154
147155 /** Russian (Русский)
@@ -149,5 +157,6 @@
150158 $messages['ru'] = array(
151159 'rped' => 'Обнаружение существования внешней страницы',
152160 'rped-desc' => 'Ставит вики-ссылки на Википедию, если страницы не существует в локальной вики, но она присутствует в Википедии',
 161+ 'rped-wikipedia-url' => 'http://ru.wikipedia.org/',
153162 );
154163

Follow-up revisions

RevisionCommit summaryAuthorDate
r65539Readd 'path' in extension credit. Probably accidently removed in r65538.raymond10:09, 26 April 2010

Comments

#Comment by Catrope (talk | contribs)   09:05, 26 April 2010

You should use $this->dieUsage() (implemented in ApiBase) for throwing errors.

Status & tagging log