r410 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r409‎ | r410 | r411 >
Date:22:12, 21 May 2002
Author:lcrocker
Status:old
Tags:
Comment:
Added image: links, other language links.
Modified paths:
  • /trunk/phpwiki/newcodebase/Article.php (modified) (history)
  • /trunk/phpwiki/newcodebase/Language.php (modified) (history)
  • /trunk/phpwiki/newcodebase/LanguageDe.php (modified) (history)
  • /trunk/phpwiki/newcodebase/LanguageEn.php (modified) (history)
  • /trunk/phpwiki/newcodebase/OutputPage.php (modified) (history)
  • /trunk/phpwiki/newcodebase/Skin.php (modified) (history)
  • /trunk/phpwiki/newcodebase/Title.php (modified) (history)
  • /trunk/phpwiki/newcodebase/wiki.phtml (modified) (history)

Diff [purge]

Index: trunk/phpwiki/newcodebase/LanguageDe.php
@@ -1,5 +1,7 @@
22 <?
33
 4+class LanguageDe extends Language {
 5+
46 /* private */ $wgValidNamespacesDe = array(
57 "Special", "Diskussion", "Benutzer", "Benutzer_diskussion",
68 "Wikipedia", "Wikipedia_diskussion"
Index: trunk/phpwiki/newcodebase/Skin.php
@@ -166,8 +166,7 @@
167167 . " | " . $this->makeLink( "Special:Whatlinkshere",
168168 wfMsg( "whatlinkshere" ), "", $wgTitle->getPrefixedURL() );
169169
170 - $ol = $this->otherLanguages();
171 - if ( "" != $ol ) { $s .= $ol; }
 170+ $s .= $this->otherLanguages();
172171 }
173172 }
174173 return $s;
@@ -227,6 +226,7 @@
228227 if ( $wgOut->isArticle() ) {
229228 $s .= " | " . $this->talkLink();
230229 }
 230+ $s .= $this->otherLanguages();
231231 return $s;
232232 }
233233
@@ -320,7 +320,28 @@
321321
322322 function otherLanguages()
323323 {
324 - return "";
 324+ global $wgOut, $wgLang;
 325+
 326+ $a = $wgOut->getLanguageLinks();
 327+ if ( 0 == count( $a ) ) { return ""; }
 328+
 329+ $s = "<br>" . wfMsg( "otherlanguages" ) . ": ";
 330+ $first = true;
 331+ foreach( $a as $l ) {
 332+ if ( ! $first ) { $s .= " | "; }
 333+ $first = false;
 334+
 335+ preg_match( "/([a-z]+):([^\|]+)/", $l, $m );
 336+ $urltemp = Title::getInterwikiLink( $m[1] );
 337+ $link = $m[2];
 338+ $text = $wgLang->getLanguageName( $m[1] );
 339+ $url = str_replace( "$1", $link, $urltemp );
 340+
 341+ if ( "" == $text ) { $text = $link; }
 342+ $style = $this->getExternalLinkAttributes( $link, $text );
 343+ $s .= "<a href=\"$url\"$style>$text</a>";
 344+ }
 345+ return $s . "\n";
325346 }
326347
327348 function bugReportsLink()
@@ -391,6 +412,19 @@
392413 return $text;
393414 }
394415
 416+ function makeInternalLink( $title, $text= "", $action = "", $target = "" )
 417+ {
 418+ $nt = Title::newFromText( $title );
 419+ if ( "Special" == $nt->getNamespace() ) {
 420+ return $this->makeLink( $title, $text );
 421+ }
 422+ if ( 0 == $nt->getArticleID() ) {
 423+ return $this->makeBrokenLink( $title, $text );
 424+ } else {
 425+ return $this->makeLink( $title, $text, $action, $target );
 426+ }
 427+ }
 428+
395429 function makeLink( $title, $text = "", $action = "", $target = "" )
396430 {
397431 global $wgServer, $wgScript, $wgArticlePath, $wgTitle;
@@ -432,6 +466,13 @@
433467 return $s;
434468 }
435469
 470+ function makeImageLink( $url, $alt = "" )
 471+ {
 472+ if ( "" == $alt ) { $alt = "[Image]"; }
 473+ $s = "<img src=\"$url\" alt=\"$alt\">";
 474+ return $s;
 475+ }
 476+
436477 function specialLink( $name )
437478 {
438479 $key = strtolower( $name );
Index: trunk/phpwiki/newcodebase/Title.php
@@ -73,6 +73,15 @@
7474 return $t;
7575 }
7676
 77+ function getInterwikiLink( $key )
 78+ {
 79+ global $wgValidInterwikis;
 80+
 81+ if ( key_exists( $key, $wgValidInterwikis ) ) {
 82+ return $wgValidInterwikis[$key];
 83+ } else return "";
 84+ }
 85+
7786 function getText() { return $this->mTextform; }
7887 function getURL() { return $this->mUrlform; }
7988 function getDBKey() { return $this->mDbkeyform; }
Index: trunk/phpwiki/newcodebase/Language.php
@@ -10,7 +10,7 @@
1111 );
1212
1313 /* private */ $wgSkinNamesEn = array(
14 - "Standard", "Star Trek", "Nostalgia", "Cologne Blue"
 14+ "Standard", "StarTrek", "Nostalgia", "CologneBlue"
1515 );
1616
1717 /* private */ $wgUserTogglesEn = array(
@@ -23,6 +23,18 @@
2424 "rememberPassword" => "Remember my password"
2525 );
2626
 27+/* private */ $wgLanguageNamesEn= array(
 28+ "w" => "English", "af" => "Afrikaans", "ar" => "Arabic",
 29+ "ca" => "Catalan", "zh" => "Chinese", "dk" => "Danish",
 30+ "nl" => "Dutch", "de" => "German", "eo" => "Esperanto",
 31+ "fr" => "French", "he" => "Hebrew", "hu" => "Hungarian",
 32+ "it" => "Italian", "ja" => "Japanese", "no" => "Norwegian",
 33+ "pl" => "Polish", "pt" => "Portugese", "ru" => "Russian",
 34+ "sh" => "Serbocroatian", "si" => "Slovene",
 35+ "simple" => "Simple English", "es" => "Spanish",
 36+ "sv" => "Swedish", "en" => "English"
 37+);
 38+
2739 /* private */ $wgAllMessagesEn = array(
2840
2941 # Bits of text used by many pages:
@@ -39,6 +51,7 @@
4052 "editthispage" => "Edit this page",
4153 "talkpage" => "Talk page",
4254 "subjectpage" => "Subject page",
 55+"otherlanguages" => "Other languages",
4356
4457 # Main script and global functions
4558 #
@@ -297,6 +310,11 @@
298311 return $wgUserTogglesEn;
299312 }
300313
 314+ function getLanguageName( $code ) {
 315+ global $wgLanguageNamesEn;
 316+ return $wgLanguageNamesEn[$code];
 317+ }
 318+
301319 function getMonthName( $key )
302320 {
303321 return ucfirst( $key );
@@ -326,6 +344,6 @@
327345 }
328346 }
329347
330 -include_once( "Language" . ucfirst( $wgLanguageCode ) . ".php" );
 348+include_once( "./Language" . ucfirst( $wgLanguageCode ) . ".php" );
331349
332350 ?>
Index: trunk/phpwiki/newcodebase/Article.php
@@ -248,6 +248,8 @@
249249
250250 if ( $minor) { $me = 1; } else { $me = 0; }
251251
 252+ # TODO: Backup to old table
 253+ #
252254 $conn = wfGetDB();
253255 $sql = "UPDATE cur SET cur_text='" . wfStrencode( $text ) .
254256 "',cur_comment='" . wfStrencode( $summary ) .
Index: trunk/phpwiki/newcodebase/OutputPage.php
@@ -7,6 +7,7 @@
88 var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
99
1010 var $mDTopen, $mLastSection; # Used for processing DL, PRE
 11+ var $mLanguageLinks;
1112
1213 function OutputPage()
1314 {
@@ -15,6 +16,7 @@
1617 $this->mHTMLtitle = $this->mPagetitle = $this->mBodytext =
1718 $this->mDebugtext = $this->mRobotpolicy = "";
1819 $this->mIsarticle = $this->mPrintable = true;
 20+ $this->mLanguageLinks = array();
1921 }
2022
2123 function addHeader( $name, $val ) { array_push( $this->mHeaders, "$name: $val" ) ; }
@@ -33,6 +35,7 @@
3436 function isArticle() { return $this->mIsarticle; }
3537 function setPrintable() { $this->mPrintable = true; }
3638 function isPrintable() { return $this->mPrintable; }
 39+ function getLanguageLinks() { return $this->mLanguageLinks; }
3740
3841 function addHTML( $text ) { $this->mBodytext .= $text; }
3942 function debug( $text ) { $this->mDebugtext .= $text; }
@@ -159,9 +162,12 @@
160163
161164 /* private */ function parseImages( $text )
162165 {
 166+ global $wgUser;
 167+ $sk = $wgUser->getSkin();
 168+
163169 $text = preg_replace(
164170 "/(^|[^[])http:\/\/([a-zA-Z0-9_\/:.~\%\-]+)\.(png|PNG|jpg|JPG|jpeg|JPEG|gif|GIF)/",
165 - "$1<img src=\"http://$2.$3\">", $text );
 171+ "$1" . $sk->makeImageLink( "http://$2.$3", "[Image]" ), $text );
166172 return $text;
167173 }
168174
@@ -223,7 +229,7 @@
224230
225231 /* private */ function replaceInternalLinks( $s )
226232 {
227 - global $wgTitle, $wgUser;
 233+ global $wgTitle, $wgUser, $wgServer, $wgUploadPath, $wgLang;
228234
229235 $tc = "[\\-,.\\(\\)' _0-9A-Za-z\\/:\\x80-\\xff]"; # from Title
230236 $sk = $wgUser->getSkin();
@@ -278,29 +284,24 @@
279285
280286 # $link, $text, and $trail should all be set now
281287 #
282 - $nt = Title::newFromText( $link );
283 - $id = $nt->getArticleID();
284 - $linkStyle = $sk->getInternalLinkAttributes( $link, $text );
285 - $isSpecialPage = ( "Special" == $nt->getNamespace() );
286 -
287 - # TODO: I should be calling a Skin function here...
288 - #
289 - if ( 0 == $id && ( ! $isSpecialPage ) ) {
290 - if ( 1 == $wgUser->getOption( "markupNewTopics" ) ) {
291 - $s .= "<a class=\"new\" href=\"" . $nt->getEditURL() .
292 - "\"$linkStyle>$text</a>" . $trail;
 288+ if ( preg_match( "/^([a-z]+):(.*)/", $link, $m ) ) {
 289+ $pre = strtolower( $m[1] );
 290+ $suf = $m[2];
 291+ if ( "image" == $pre ) {
 292+ $s .= $sk->makeImageLink( "$wgServer$wgUploadPath/" .
 293+ $suf, $text );
293294 } else {
294 - $s .= $text . "<a href=\"" . $nt->getEditURL() .
295 - "\"$linkStyle>?</a>" . $trail;
 295+ $l = $wgLang->getLanguageName( $pre );
 296+ if ( "" == $l ) {
 297+ $s .= $sk->makeInternalLink( $link, $text );
 298+ } else {
 299+ array_push( $this->mLanguageLinks, "$pre:$suf" );
 300+ }
296301 }
297302 } else {
298 - $s .= "<a href=\"" . $nt->getFullURL() . "\"$linkStyle>$text";
299 - if ( preg_match( "/^([a-z]+)/", $trail, $m ) ) {
300 - $s .= $m[1];
301 - $trail = substr( $trail, strlen( $m[1] ) );
302 - }
303 - $s .= "</a>" . $trail;
 303+ $s .= $sk->makeInternalLink( $link, $text );
304304 }
 305+ $s .= $trail;
305306 }
306307 return $s;
307308 }
Index: trunk/phpwiki/newcodebase/wiki.phtml
@@ -13,13 +13,13 @@
1414 include_once( "./Title.php" );
1515 include_once( "./Article.php" );
1616
17 -global $action, $title, $search $target; # From query string
 17+global $action, $title, $search, $target; # From query string
1818 global $wgUser, $wgLang, $wgOut, $wgTitle; # Objects to handle output
1919 global $wgArticle, $wgDeferredUpdateList;
2020
2121 $wgOut = new OutputPage();
2222 $wgLangClass = "Language" . ucfirst( $wgLanguageCode );
23 -$wgLang = new $wgLanguageClass();
 23+$wgLang = new $wgLangClass();
2424 $wgOut->addHeader( "Content-type", "text/html; charset=iso-8859-1" );
2525
2626 $wgUser = new User();
Index: trunk/phpwiki/newcodebase/LanguageEn.php
@@ -1,7 +1,7 @@
22 <?
33 # See language.doc
44
5 -class LanguageEn {
 5+class LanguageEn extends Language {
66 # Inherit everything
77 }
88

Follow-up revisions

RevisionCommit summaryAuthorDate
r97420Messages added in r410platonides14:59, 18 September 2011

Status & tagging log