I'm making my mediawiki-driven senior project for this semester. It is about creating a thesaurus for bikol languages. I started editing pages and also importing pages manually. So far, all the changes work. Now, I'm making the core function of my project-thesaurus. I implemented a string search algorithm in a php file(but not yet on the special file), which I will be using in the search function on the SpecailThesaurus.php file. I'm making a special page on the /includes directory and also on the /extensions directory named "SpecialThesaurus.php".
Problems: -How can I set the action attribute in "form" so that it displays all the output on the page $SERVER['PHP_SELF'];
-How can I enable this script "SpecialThesaurus.php" so that it shows after a user adds/edit a page?
Thanks. (^_^)
On the /extensions directory, the "SpecialThesaurus.php" includes this code: --------------- <?php $wgExtensionFunctions[] = "wfExtensionSpecialThesaurus";
function wfExtensionSpecialThesaurus() { global $wgMessageCache; $wgMessageCache->addMessages(array('thesaurus' => 'WikiBiTs Thesaurus page'));
require_once('includes/SpecialPage.php'); SpecialPage::addPage(new SpecialPage('Thesaurus')); } ?> ---------------
On the /includes directory, the "SpecialThesaurus.php" includes this code: --------------- <?php if( !defined( 'MEDIAWIKI' ) ) die(); $wgExtensionCredits['validextensionclass'][] = array( 'name' => 'Thesaurus for Biko languages', 'author' =>'Kathleen Jane P. Borja', 'url' => 'http://www.mediawiki.org/wiki/User:Kathjane', 'description' => 'This Extension searches for bikol word for a given literary input (poems, short stories, etc.), tags the searched word with bikol synonym according to origin (Bikol-Naga, Bikol-Masbate, etc.) and user type (Student, College Graduate, or Professional). ' );
function wfSpecialThesaurus() { $searchboxtext = "Search for Bikol words"; $tagboxtext = "Tag with Bikol Synonym"; global $wgOut;
$result=<<<ENDFORM
<!-- Thesaurus Extension by Borja, Kathleen --> <table border="0" align="left" width="650" cellspacing="0" cellpadding="0"> <tr> <td width="100%" align="left" bgcolor=""> <form name="searchbox" action="" method="get" class="searchbox"> Search : <input class="searchboxinput" name="searchkword" type="text" value="{$searchboxtext}" size="50" /> <input type="submit" name="submitsearch" value="Go" /> <input type="reset" name="cancelsearch" value="Cancel"/><br><br> Results:<br> <textarea name="resultarea" cols="60" rows="10"></textarea><br><br> Tag with: <input type="text" name="tagbox" value={$tagboxtext}" size="50" /> Origin: <select> <option name="default" />Bicol-Naga <option name="bicolmasbate" />Bicol-Masbate <option name="bicolragay" />Bicol-Ragay <option name="bicollegazpi" />Bicol-Legazpi <option name="others" />Others </select> User Category: <select> <option name="student" />Student <option name="collegegraduate" />College Graduate <option name="professional" />Professional <option name="others" />Others </select><br><br> <input type="submit" name="saveall" value="Save" /> <input type="reset" name="cancelall" value="Cancel" /> </form> </td> </tr> </table> <!-- Thesaurus Extension End - --> ENDFORM; $wgOut->addHTML($result); return true; } ?> ---------------
2009/7/25 Kathleen Borja jane88borj@yahoo.com:
I'm making my mediawiki-driven senior project for this semester. It is about creating a thesaurus for bikol languages. I started editing pages and also importing pages manually. So far, all the changes work. Now, I'm making the core function of my project-thesaurus. I implemented a string search algorithm in a php file(but not yet on the special file), which I will be using in the search function on the SpecailThesaurus.php file. I'm making a special page on the /includes directory and also on the /extensions directory named "SpecialThesaurus.php".
Problems: -How can I set the action attribute in "form" so that it displays all the output on the page $SERVER['PHP_SELF'];
-How can I enable this script "SpecialThesaurus.php" so that it shows after a user adds/edit a page?
Thanks. (^_^)
On the /extensions directory, the "SpecialThesaurus.php" includes this code:
The code you're quoting uses pretty old conventions, and I'm not sure it'll still work correctly. What you wanna do is the following:
In extensions/Thesaurus/SpecialThesaurus.php:
class SpecialThesaurus extends SpecialPage { function __construct() { parent::__construct( 'Thesaurus' ); }
function execute( $par ) { global $wgOut; $this->setHeaders(); $this->setTitle( 'Some title' ); $wgOut->addHTML( "Example HTML" ); // $par is the subpage parameter, i.e. for Special:Thesaurus/Foo $par == 'Foo' // To get the URL to this special page, use $this->getTitle()->getFullURL() } }
In extensions/Thesaurus/Thesaurus.php:
$wgSpecialPages['Thesaurus'] = 'SpecialThesaurus'; $wgAutoloadClasses['SpecialThesaurus'] = dirname(__FILE__) . '/SpecialThesaurus.php';
Note that the special page itself should also be in extensions/Thesaurus/ , not in includes/ .
Roan Kattouw (Catrope)
Roan Kattouw <roan.kattouw <at> gmail.com> writes:
On the /extensions directory, the "SpecialThesaurus.php" includes this code:
The code you're quoting uses pretty old conventions, and I'm not sure it'll still work correctly. What you wanna do is the following:
In extensions/Thesaurus/SpecialThesaurus.php:
class SpecialThesaurus extends SpecialPage { function __construct() { parent::__construct( 'Thesaurus' ); }
function execute( $par ) { global $wgOut; $this->setHeaders(); $this->setTitle( 'Some title' ); $wgOut->addHTML( "Example HTML" ); // $par is the subpage parameter, i.e. for
Special:Thesaurus/Foo $par == 'Foo' // To get the URL to this special page, use $this->getTitle()->getFullURL() } }
In extensions/Thesaurus/Thesaurus.php:
$wgSpecialPages['Thesaurus'] = 'SpecialThesaurus'; $wgAutoloadClasses['SpecialThesaurus'] = dirname(__FILE__) . '/SpecialThesaurus.php';
Note that the special page itself should also be in extensions/Thesaurus/ , not in includes/ .
Roan Kattouw (Catrope)
Thank you for the quick response. I'm sorry to reply you back late. I'm in school right now. That's why I was able to have Internet connection. Anyway, I copied and pasted the codes you suggested. I put the first one in extensions/Thesaurus/SpecialThesaurus.php wherein the class SpecialThesaurus is placed. So, the code looks like this: <?php class SpecialThesaurus extends SpecialPage { function __construct() { parent::__construct( 'Thesaurus' ); }
function execute( $par ) { global $wgOut; $this->setHeaders(); $this->setTitle( 'Some title' ); $wgOut->addHTML( "Example HTML" ); // $par is the subpage parameter, i.e. for Special:Thesaurus/Foo $par == 'Foo' // To get the URL to this special page, use $this->getTitle()->getFullURL() } } ?>
Then, I put the following lines in extensions/Thesaurus/Thesaurus.php: <?php $wgSpecialPages['Thesaurus'] = 'SpecialThesaurus'; $wgAutoloadClasses['SpecialThesaurus'] = dirname(__FILE__) . '/SpecialThesaurus.php'; ?>
Problems: -Is there something that I am lacking? Why is it that there's no output when I type in the URL? My URL looks was : http://localhost/wikibits/index.php/SpecialThesaurus.php. I am running the script on a localhost server. Is there something wrong with the URL? I can hardly view the special page... -If I'll be adding some form elements, where shall I put them?on the SpecialThesaurus.php or Thesaurus.php? -So, for now, I have 2 files in the extensions/Thesaurus directory. Is it right? Again, thanks a lot. (^_^)
Roan Kattouw <roan.kattouw <at> gmail.com> writes:
On the /extensions directory, the "SpecialThesaurus.php" includes this code:
The code you're quoting uses pretty old conventions, and I'm not sure it'll still work correctly. What you wanna do is the following:
In extensions/Thesaurus/SpecialThesaurus.php:
class SpecialThesaurus extends SpecialPage { function __construct() { parent::__construct( 'Thesaurus' ); }
function execute( $par ) { global $wgOut; $this->setHeaders(); $this->setTitle( 'Some title' ); $wgOut->addHTML( "Example HTML" ); // $par is the subpage parameter, i.e. for
Special:Thesaurus/Foo $par == 'Foo' // To get the URL to this special page, use $this->getTitle()->getFullURL() } }
In extensions/Thesaurus/Thesaurus.php:
$wgSpecialPages['Thesaurus'] = 'SpecialThesaurus'; $wgAutoloadClasses['SpecialThesaurus'] = dirname(__FILE__) . '/SpecialThesaurus.php';
Note that the special page itself should also be in extensions/Thesaurus/ , not in includes/ .
Roan Kattouw (Catrope)
Thank you for the quick response. I'm sorry to reply you back late. Anyway, I copied and pasted the codes you suggested. I put the first one in extensions/Thesaurus/SpecialThesaurus.php wherein the class SpecialThesaurus is placed. So, the code looks like this: <?php class SpecialThesaurus extends SpecialPage { function __construct() { parent::__construct( 'Thesaurus' ); }
function execute( $par ) { global $wgOut; $this->setHeaders(); $this->setTitle( 'Some title' ); $wgOut->addHTML( "Example HTML" ); // $par is the subpage parameter, i.e. for Special:Thesaurus/Foo $par == 'Foo' // To get the URL to this special page, use $this->getTitle()->getFullURL() } } ?>
Then, I put the following lines in extensions/Thesaurus/Thesaurus.php: <?php $wgSpecialPages['Thesaurus'] = 'SpecialThesaurus'; $wgAutoloadClasses['SpecialThesaurus'] = dirname(__FILE__) . '/SpecialThesaurus.php'; ?>
Problems: -Why is it that there's no output when I type in the URL? My URL looks like this : http://localhost/wikibits/index.php/SpecialThesaurus.php. I am running the script on a localhost server. Is there something wrong with the URL? I can hardly test the special page... -If I'll be adding some form elements, where shall I put them?on the SpecialThesaurus.php or Thesaurus.php? -So, for now, I have 2 files in the extensions/Thesaurus directory. Is it right? Again, thanks a lot. (^_^)
Kathleen Borja wrote:
-If I'll be adding some form elements, where shall I put them?on the SpecialThesaurus.php or Thesaurus.php?
-So, for now, I have 2 files in the extensions/Thesaurus directory. Is it right?
Again, thanks a lot. (^_^)
Yes, it is right. You create a really light Thesaurus.php that is run on every page view, and a bigger file SpecialThesaurus.php which is only loaded when Special:Thesaurus is requested.
You would add the form elements into SpecialThesaurus.php, at the execute method. You can change the $wgOut->addHTML() to show whatever do want. You don't need to hardcode the html, though. You can use Xml::Element() for that.
Platonides <platonides <at> gmail.com> writes:
Yes, it is right. You create a really light Thesaurus.php that is run on every page view, and a bigger file SpecialThesaurus.php which is only loaded when Special:Thesaurus is requested.
You would add the form elements into SpecialThesaurus.php, at the execute method. You can change the $wgOut->addHTML() to show whatever do want. You don't need to hardcode the html, though. You can use Xml::Element() for that.
Thanks for the response. Now, I have a clearer picture on what I'll be putting on those files especially on the SpecialThesaurus.php file to where the major elements are placed. And also, I now know that there is no need to hardcode the html for I can use the Xml::Element()although I am not yet familiar with the xml tags. I'll read tutorials on xml.
Questions: > On $wgOut->addHTML() - You said that I can change $wgOut->addHTML() to show whatever I want. So, what are the things that need to be considered so that I can use $wgOut->addHTML()? Is there syntax to be followed for making it? > How can I test if my SpecialThesaurus.php is working? Is it like typing the URL (http://localhost/wikibits/index.php/Special:Thesaurus) in the address bar? > I wanted to create a new tab for the SpecialThesaurus page. Where and how can I create it so that it will be included among the page menu tabs - page,dicussion,edit,history, delete, move, etc? What is the proper page to where I can put it or shall I create also a new special page for it?
> Also, I can hardly connect to database `wikidb`. Maybe there's already a pre-defined function for it.I just can't find it.
> Is it okey if I let you check the necessary files if I finished making them? Thanks. (^_^) P.S. I'm sorry if I piled up my questions.. Maybe it can be a harsh on you.
2009/7/28 Kathleen Borja jane88borj@yahoo.com:
Thanks for the response. Now, I have a clearer picture on what I'll be putting on those files especially on the SpecialThesaurus.php file to where the major elements are placed. And also, I now know that there is no need to hardcode the html for I can use the Xml::Element()although I am not yet familiar with the xml tags. I'll read tutorials on xml.
There's documentation at http://svn.wikimedia.org/doc/classXml.html
Questions: > On $wgOut->addHTML() - You said that I can change $wgOut->addHTML() to show whatever I want. So, what are the things that need to be considered so that I can use $wgOut->addHTML()? Is there syntax to be followed for making it?
Just use $wgOut->addHTML("any HTML here"); It's customary to build the HTML with Xml:: functions.
> How can I test if my SpecialThesaurus.php is working? Is it like typing the URL (http://localhost/wikibits/index.php/Special:Thesaurus) in the address bar?
Yes.
> I wanted to create a new tab for the SpecialThesaurus page. Where and how can I create it so that it will be included among the page menu tabs - page,dicussion,edit,history, delete, move, etc? What is the proper page to where I can put it or shall I create also a new special page for it?
Look at http://www.mediawiki.org/wiki/Manual:Hooks/SkinTemplateTabs
> Also, I can hardly connect to database `wikidb`. Maybe there's already a pre-defined function for it.I just can't find it.
Use $dbr = wfGetDb( DB_SLAVE ); for a read connection, $dbw = wfGetDb( DB_MASTER ); for a read/write connection. wfGetDb() returns a DatabaseBase object which has methods such as select() and insert(); see http://svn.wikimedia.org/doc/classDatabaseBase.html for documentation.
> Is it okey if I let you check the necessary files if I finished making them?
Sure.
Roan Kattouw (Catrope)
Here are the files I've created for SpecialThesaurus extension:
SpecialThesaurus.php SpecialThesaurus_body.php SpecialThesaurus.alias.php SpecialThesaurus.i18n.php
The SpecialThesaurus_body.php file I've sent to Roan Kattouw this day consists of the major form elements. The contents are too long to be displayed here that's why I just sent it to Roan Kattouw's email. For now, this file allows user to search for keyword in the given sentence "The quick brown fox jumps over the lazy dog near the bank of the river." If a given keyword is found, it makes a link to that searched keyword and a form including a input box for tag, select tag for origins, etc. Still, the form is not yet functioning... But, this is how it's gonna be...
Questions:
About the contents on the SpecialThesaurus_body.php, am I on the right track?
About connecting to db, I used $dbr = wfGetDb(DB_SLAVE) command. How can I
check if it was really connected to the db? How can I fetch arrays from db? Are there db functions specially made for mediawiki that I can use?
What kind of Hook shall I use if I wanted the elements in SpecialThesaurus
(form including input boxes, etc.) be included some part of an article page? Let's say I wanted to put the form and other elements on the right part of the page.. How will I do it?
With the three other files, what kind of contents shall I add to them?
I badly needed your help, guys. Thanks (^_^)
2009/8/7 Kathleen Borja jane88borj@yahoo.com:
Here are the files I've created for SpecialThesaurus extension:
SpecialThesaurus.php SpecialThesaurus_body.php SpecialThesaurus.alias.php SpecialThesaurus.i18n.php
The SpecialThesaurus_body.php file I've sent to Roan Kattouw this day consists of the major form elements. The contents are too long to be displayed here that's why I just sent it to Roan Kattouw's email.
I never got it. Please verify you've got the right address.
Questions:
About the contents on the SpecialThesaurus_body.php, am I on the right track?
About connecting to db, I used $dbr = wfGetDb(DB_SLAVE) command. How can I
check if it was really connected to the db? How can I fetch arrays from db? Are there db functions specially made for mediawiki that I can use?
If connecting with the DB fails, an error page will be displayed with your user and your code won't run past the wfGetDb statement, so you don't have to worry about that. Methods of the $dbr object are documented at http://svn.wikimedia.org/doc/classDatabaseBase.html . A simple example would be:
$res = $dbr->select( 'tablename', array( 'field1', 'field2' ), array( 'field1' => 'foo', 'field3=field1' ), __METHOD__ ); foreach ( $res as $row ) { // Do something with $row->field1, $row->field2 }
Note that $res is NOT an array, just a special object that happens to be foreach()able. PHP's array_*() functions WILL NOT WORK on it. That shouldn't be a problem though, because in most cases foreach() is all you wanna use.
What kind of Hook shall I use if I wanted the elements in SpecialThesaurus
(form including input boxes, etc.) be included some part of an article page? Let's say I wanted to put the form and other elements on the right part of the page.. How will I do it?
I'm not sure; I'll have to look that up.
With the three other files, what kind of contents shall I add to them?
Read the extensions manual page, in particular this section: http://www.mediawiki.org/wiki/Manual:Extensions#Internal_organization_of_an_...
Roan Kattouw (Catrope)
I've sent you an email (roan.kattouw@gmail.com). I hope I've got the right email.
I was able to connect to the database using the wfGetDb statement. I now use the $dbr object to access the fields and values in the database. I used the select() method. I'm learning on how to use the especially the insert() method for it will now use the write method. Can you give me an example of the insert()?
Now, I made Special Page. But, when a link in a special page is clicked, it must redirect to another page. But what I did is I made another special page for it to redirect to. Is there an easy way to make a page having the special page template?
Also, I find it hard to make a pop up window when a link is clicked.
Thanks again. ^_^
2009/8/15 Kathleen Borja jane88borj@yahoo.com:
I've sent you an email (roan.kattouw@gmail.com). I hope I've got the right email.
I was able to connect to the database using the wfGetDb statement. I now use the $dbr object to access the fields and values in the database. I used the select() method. I'm learning on how to use the especially the insert() method for it will now use the write method. Can you give me an example of the insert()?
You'll need a write connection to be able to insert:
$dbw = wfGetDb( DB_MASTER ); // As opposed to DB_SLAVE, which is read-only
// Insert one row: $dbw->insert( 'tablename', array( 'field1' => 'value1', 'field2' => 'value2' ), __METHOD__ );
// Insert two rows and ignore errors such as duplicate indexes $dbw->insert( 'tablename', array( array( 'field1' => 'value1', 'field2' => 'value2' ), array( 'field1' => 'value3', 'field2' => 'value4' ) ), __METHOD__, array( 'IGNORE' ) );
Documentation for insert() and other $dbr/$dbw methods is at http://svn.wikimedia.org/doc/classDatabaseBase.html#e620764adec943ea9b52d055... . You may also be interested in update() and replace().
Now, I made Special Page. But, when a link in a special page is clicked, it must redirect to another page. But what I did is I made another special page for it to redirect to. Is there an easy way to make a page having the special page template?
What do you mean redirect to another page? Do you just want a simple link to another page, or do you want something more complex?
Roan Kattouw (Catrope)
mediawiki-api@lists.wikimedia.org