r13884 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r13883‎ | r13884 | r13885 >
Date:09:46, 27 April 2006
Author:magnusmanske
Status:old
Tags:
Comment:
Adding MediaWiki extension capability (now works live from database)
Modified paths:
  • /trunk/wiki2xml/php/content_provider.php (modified) (history)
  • /trunk/wiki2xml/php/extension.php (modified) (history)
  • /trunk/wiki2xml/php/w2x.php (modified) (history)
  • /trunk/wiki2xml/php/wiki2xml.php (modified) (history)

Diff [purge]

Index: trunk/wiki2xml/php/wiki2xml.php
@@ -22,6 +22,7 @@
2323 "br" => "xhtml:br",
2424 "div" => "xhtml:div",
2525 "span" => "xhtml:span",
 26+ "big" => "xhtml:big",
2627 "small" => "xhtml:small",
2728 "sub" => "xhtml:sub",
2829 "sup" => "xhtml:sup",
Index: trunk/wiki2xml/php/extension.php
@@ -50,7 +50,7 @@
5151 function execute( $par = null ) { # Checked for HTML and MySQL insertion attacks
5252 global $wgOut, $wgRequest, $wgUser, $wgTitle, $IP;
5353 $fname = 'Special::Tasks:execute';
54 - global $xmlg , $html_named_entities_mapping_mine;
 54+ global $xmlg , $html_named_entities_mapping_mine, $content_provider;
5555 include_once ( "default.php" ) ;
5656 $xmlg['sourcedir'] = $IP.'/extensions/wiki2xml' ;
5757 include_once ( "w2x.php" ) ;
Index: trunk/wiki2xml/php/w2x.php
@@ -19,7 +19,7 @@
2020 return ((float)$usec + (float)$sec);
2121 }
2222
23 -function get_form () {
 23+function get_form ( $as_extension = false ) {
2424 global $xmlg ;
2525 $optional = array () ;
2626 if ( isset ( $xmlg['docbook']['command_pdf'] ) ) {
@@ -34,8 +34,9 @@
3535 }
3636 $optional = "<br/>" . implode ( "<br/>" , $optional ) ;
3737
 38+ if ( $as_extension ) $site = "<input type='hidden' name='site' value=''/>" ;
 39+ else $site = "Site : http://<input type='text' name='site' value='".$xmlg["site_base_url"]."'/>/index.php<br/>" ;
3840
39 -
4041 return "<form method='post'>
4142 <h2>Paste article list or wikitext here</h2>
4243 <table border='0' width='100%'><tr>
@@ -54,7 +55,7 @@
5556 <INPUT checked type='radio' name='whatsthis' value='articlelist'>a list of articles
5657 <br/>
5758
58 -Site : http://<input type='text' name='site' value='".$xmlg["site_base_url"]."'/>/index.php<br/>
 59+{$site}
5960 Title : <input type='text' name='document_title' value='' size=40/><br/>
6061 <input type='checkbox' name='add_gfdl' value='1' checked>Include GFDL (for some output formats)</input><br/>
6162 <input type='checkbox' name='keep_categories' value='1' checked>Keep categories</input><br/>
@@ -85,7 +86,11 @@
8687 if ( isset ( $_POST['doit'] ) ) { # Process
8788 $wikitext = stripslashes ( $_POST['text'] ) ;
8889
89 - $content_provider = new ContentProviderHTTP ;
 90+ if( !defined( 'MEDIAWIKI' ) ) { # Stand-alone
 91+ $content_provider = new ContentProviderHTTP ;
 92+ } else { # MediaWiki extension
 93+ $content_provider = new ContentProviderMySQL ;
 94+ }
9095 $converter = new MediaWikiConverter ;
9196
9297 $xmlg["book_title"] = $_POST['document_title'] || 'document';
@@ -245,7 +250,7 @@
246251 print get_form () ;
247252 print "</body></html>" ;
248253 } else { # MediaWiki extension
249 - $out = get_form () ;
 254+ $out = get_form ( true ) ;
250255 }
251256
252257 }
Index: trunk/wiki2xml/php/content_provider.php
@@ -269,4 +269,64 @@
270270
271271 }
272272
 273+# Access through text file structure
 274+class ContentProviderMySQL extends ContentProviderHTTP {
 275+
 276+ function do_get_contents ( $title ) {
 277+ return $this->get_page_text ( $title ) ;
 278+ }
 279+
 280+ /**
 281+ Called from outside
 282+ */
 283+ function get_wiki_text ( $title , $do_cache = false ) {
 284+ $title = trim ( $title ) ;
 285+ if ( $title == "" ) return "" ; # Just in case...
 286+ if ( $this->first_title == "" ) {
 287+ $this->first_title = $title ;
 288+ }
 289+ $text = $this->get_page_text ( $title ) ;
 290+ return $text ;
 291+ }
 292+
 293+ function get_file_location ( $ns , $title ) {
 294+ return get_file_location_global ( $this->basedir , $ns , $title , false ) ;
 295+ }
 296+
 297+ function get_page_text ( $page , $allow_redirect = true ) {
 298+ /*
 299+ $filename = $this->get_file_location ( 0 , $page ) ;
 300+ $filename = $filename->fullname . $this->file_ending ;
 301+ if ( !file_exists ( $filename ) ) return "" ;
 302+ $text = trim ( file_get_contents ( $filename ) ) ;
 303+ */
 304+
 305+ $title = Title::newFromText ( $page ) ;
 306+ $article = new Article ( $title ) ;
 307+ $text = $article->getContent () ;
 308+
 309+ # REDIRECT?
 310+ if ( $allow_redirect && strtoupper ( substr ( $text , 0 , 9 ) ) == "#REDIRECT" ) {
 311+ $text = substr ( $text , 9 ) ;
 312+ $text = array_shift ( explode ( "\n" , $text , 2 ) ) ;
 313+ $text = str_replace ( "[[" , "" , $text ) ;
 314+ $text = str_replace ( "]]" , "" , $text ) ;
 315+ $text = ucfirst ( trim ( $text ) ) ;
 316+ $text = $this->get_page_text ( $text , false ) ;
 317+ }
 318+ return $text ;
 319+ }
 320+
 321+ function get_internal_link ( $target , $text ) {
 322+ $file = $this->get_file_location ( 0 , $target ) ;
 323+ if ( !file_exists ( $file->fullname.$this->file_ending ) ) return $text ;
 324+ else return "<a href='browse_texts.php?title=" . urlencode ( $target ) . "'>{$text}</a>" ;
 325+ }
 326+
 327+ function do_show_images () {
 328+ return false ;
 329+ }
 330+
 331+}
 332+
273333 ?>

Follow-up revisions

RevisionCommit summaryAuthorDate
r81574followup r13884 add CASCADE so that if the tables are created a second...mah22:20, 5 February 2011

Status & tagging log