Project:Support desk/Sections/PHP

__NEWSECTIONLINK__

= PHP Error Support =

(RESOLVED) Pages imported by ImportTextFile.php NOT searchable

 * Revive from Project:Support desk/Archives/PHP/001


 * MediaWiki: 1.8.3
 * PHP: 5.2.0
 * MySQL: 5.0.27
 * URL:

I am using ImportTextFile.php to import a number of pages and they show up in Recent Changes.

But if I do a search on some text that I know is in the pages, the results are NOT showing them.

Is there a way that I can ensure that these pages are also searchable?

Thanks.

—68.147.72.69 06:34, 15 March 2008 (UTC)


 * Run the updateSearchIndex.php maintenance script. Emufarmers 02:23, 21 March 2008 (UTC)

That didn't work for imported pages as these pages were not selected during the run of the updateSearchIndex.php. The problem seems to be in the SELECT statement in updateSearchIndex.inc where "iaisrecentchanges" and "iaispage" tables are matched up to find the pages to be updated. The original SELECT statement is SELECT ... FROM $recentchanges JOIN $page on    rc_cur_id=page_id AND rc_this_oldid=page_latest and since an imported page has a clean slate of attributes, they are NOT selected.

Looking at the actual attributes in the imported pages, rc_last_oldid is always set to 0, thus by changing the SELECT statement to SELECT ... FROM $recentchanges JOIN $page on     rc_cur_id=page_id AND (rc_this_oldid=page_latest OR rc_last_oldid=0) then those imported pages are also selected.

I also believe that newer versions of mediawiki might have fixed this.

68.147.72.69 16:21, 25 March 2008 (UTC)
 * rebuildtextindex.php may do the work for this --Ans 03:53, 9 December 2009 (UTC)

Hack for rating of articles

 * MediaWiki 	1.13.1
 * PHP 	5.2.9 (cgi)
 * MySQL 	5.1.30-percona-log
 * URL: nlauer.com/wiki

Hi everybody!

I read a few days the book Packt - MediaWiki Administrators' Tutorial Guide and in Chapter 9 is a hack for rating of articles including the code to a special page with the report!

But I implemented in my Wiki and presented the following error:

There was a syntax error in the search database. The last attempt to search the database was:

(SQL query hidden)

function ". MySQL returned error "1146: Table 'theend35.mw_' does not exist."

My Wiki is the version 1.13 but the version used in the book is to 1.9

Below is the PHP code that can also be caught in the publisher's website: http://www.packtpub.com/support/book/Mediawiki

RateArticle.php PHP Code: <? if ( ! defined( 'MEDIAWIKI' ) ) die; require_once("DatabaseFunctions.php"); function wfRateArticleForm { global $wgArticle, $wgUser, $wgScriptPath; if(isset($_GET['rated'])&& $_GET['rated'] == "successfully") { $wgArticle->purge; } $s = getArticleRating; if($wgUser->isLoggedIn) { if(!articleRated) { $s .= ' Rate this Article:  1  2  3  4  5  getID. '"> getTitle->getPrefixedText.'"> getName. '">  '; } } echo $s; } function getArticleRating { global $wgArticle, $wgDBprefix; $articleID = $wgArticle->getID; $totalRatings = 0; $totalPoints = 0; $averageRating = 0; $sql = "SELECT totalRatings, totalPoints FROM {$wgDBprefix} articlerating WHERE articleID=$articleID"; $res = wfQuery( $sql, DB_READ ); if( $s = wfFetchObject( $res ) ) { $totalRatings = $s->totalRatings; $totalPoints = $s->totalPoints; } if($totalRatings>0) { $averageRating = $totalPoints/$totalRatings; return "Average Rating for this Article is " .sprintf("%.2f",$averageRating). "  ( out of 5.00 ) after $totalRatings Ratings"; } else { return "No rating has been done for this Article."; } } function articleRated { global $wgArticle, $wgUser, $wgDBprefix; $articleID = $wgArticle->getID; $userName = $wgUser->getName; $sql = "SELECT * FROM {$wgDBprefix}articleratinghistory WHERE articleID=$articleID and userName = '$userName'"; $res = wfQuery( $sql, DB_READ ); if( $s = wfFetchObject( $res ) ) { return true; } else { return false; } } ?>

saverating.php PHP Code:

=
================================= Save it in theroot folder of your installation

=
=================================

require_once( './includes/WebStart.php' ); $dbw =& wfGetDB( DB_MASTER ); $dbw->begin; $sql = "update {$wgDBprefix}articlerating set `totalRatings` = `totalRatings` + 1, `totalPoints` = `totalPoints` + '$_POST[rating]' where `articleID` = '$_POST[articleID]' "; $res = $dbw->query($sql); if($dbw->affectedRows==0) { $sql = "insert into {$wgDBprefix}articlerating set `articleID` = '$_POST[articleID]', `articleName` = '$_POST[articleTitle]', `totalRatings` = 1, `totalPoints` = '$_POST[rating]' "; $res = $dbw->query( $sql); } $sql = "insert into {$wgDBprefix}articleratinghistory set `articleID` = '$_POST[articleID]', `userName` = '$_POST[userName]', `articleRating` = '$_POST[rating]'"; $res = $dbw->query( $sql); $dbw->commit; he ader("Location: index.php?title=".$_POST ['articleTitle']."&rated=successfully");

SpecialPageRating.php PHP Code:

=
==================== Save inside the extensions folder

=
====================

 'Article Ratings', 'author' => 'Mizanur Rahman', 'url' => '' ); function wfSpecialPageRating { global $wgMessageCache; SpecialPage::addPage( new PageRating ); $wgMessageCache->addMessage( 'pagerating', 'Article Ratings' ); $wgMessageCache->addMessage( 'pagerating-header', "This page lists the $1 ranked pages on the wiki." ); $wgMessageCache->addMessage( 'pagerating-limitlinks', 'Show up to $1 pages' ); $wgMessageCache->addMessage( 'pagerating-showing', 'Found $1 pages; listing newest first:' ); $wgMessageCache->addMessage( 'pagerating-none', 'No entries were found.' ); } class PageRating extends IncludableSpecialPage { var $limit = 50; function PageRating { SpecialPage::SpecialPage( 'PageRating', '', true, false, 'default', true ); } function execute( $par ) { global $wgOut; $this->setLimit( $par ); if( !$this->mIncluding ) { $this->setHeaders; $wgOut->addWikiText( wfMsg( 'pagerating-header', $this->limit )); $wgOut->addHTML( $this->makeLimitLinks ); } $dbr =& wfGetDB( DB_SLAVE ); $res = $dbr->query( "SELECT * from articlerating ORDER BY articleID DESC LIMIT 0,{$this->limit}" ); $count = $dbr->numRows( $res ); if( $count > 0 ) { if( !$this->mIncluding ) $wgOut->addWikiText( wfMsg ( 'pagerating-showing', $count ) ); $wgOut->addHTML( " \n" ); } else { $wgOut->addWikiText( wfMsg( 'pagerating-none' ) ); } $dbr->freeResult( $res ); } function setLimit( $par ) { if( $par ) { $this->limit = intval( $par ); } else { global $wgRequest; if( $limit = $wgRequest->getIntOrNull( 'limit' ) ) { $this->limit = $limit; } else { $this->limit = 50; } } } function makeListItem( $row, $i ) { global $wgUser; $title = $row->articleName; $ratingpoint = $row->totalPoints; $totalrating = $row->totalRatings; $currentRating = sprintf("%.2f",$ratingpoint/$totalrating); if( !is_null( $title ) ) { return( " $i.  $title $currentRating $totalrating  \n"); } else { return( "\n" ); } } function makeLimitLinks { global $wgUser; $skin = $wgUser->getSkin; $title = Title::makeTitle( NS_SPECIAL, 'PageRating' ); $limits = array( 10, 20, 30, 50, 100, 150 ); foreach( $limits as $limit ) { if( $limit != $this->limit ) { $links[] = $skin->makeKnownLinkObj( $title, $limit, 'limit=' . $limit ); } Else { $links[] = (string)$limit; } } return( wfMsgHtml( 'pagerating-limitlinks', implode( ' | ', $links ) ) ); } } } else { echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" ); die( -1 ); } ?>
 * 1) Don't show the navigation if we're including the page
 * 1) Make tabled list

Creating tables

Code: CREATE TABLE `articlerating` (`articleID` INT NOT NULL, `articleName` VARCHAR( 250 ) NOT NULL,`totalRatings` INT NOT NULL,`totalPoints` INT NOT NULL, PRIMARY KEY ( `articleID` ));

Code: CREATE TABLE `articleratinghistory` (`articleID` INT NOT NULL ,`userName` VARCHAR( 50 ) NOT NULL ,`articleRating` TINYINT NOT NULL );

Our next step will be to add a hook for the implemented function. In order to do so, we have to add the following line at the end of our LocalSettings.php file in the root folder of the wiki installation. This hook runs when an event named AfterArticleDisplayed occurs:

PHP Code: $wgHooks['AfterArticleDisplayed'][] = 'wfRateArticleForm'; After this we have to add our extension file at the end of LocalSettings.php. The following code needs to be added for this purpose:

PHP Code: require_once("extensions/RateArticle.php"); We have defined our hook for the extended functionality, and we now need to show this functionality to the user. To implement this, we have to modify our skin file. So let's open our default skin file MonoBook.php file from the skins directory. In the file, try to find the footer code blocks, which start with the following code:

PHP Code: and add the following code section just before the mentioned code section: <? global $wgTitle, $wgOut; if($wgOut->isArticle && $wgTitle->getArticleId>1) { ?> <? wfRunHooks( 'AfterArticleDisplayed'); ?> <? } ?>

Can you help to correct the error?

—Lauer 13:14, 23 December 2009 (UTC)

PHP 5.3 Problem Still Exists
MW's problems with PHP 5.3 appear still not resolved, despite the fix that was reported as http://bugs.php.net/bug.php?id=50394. I'm still receiving similar error messages (eg Warning: Parameter 5 to fnHierarchySaveHook expected to be a reference, value given in ...includes/Hooks.php on line 117) as well as for the Language.php module.
 * This happens because because the function being called expects the parameter to be passed by reference, but the hook doesn't pass it by reference. If your function is called by ArticleSave, you can see that the $minor parameter is not passed by reference. You'll need to remove the "&" before that paramter and it should work again. i Alex  08:18, 30 January 2010 (UTC)

When logging in users get Fatal error: Class 'SpecialResetpass' not found

 * MediaWiki version: 1.11.0
 * PHP version: 5.2.6
 * MySQL version: 5.0.45
 * URL: http://www.automaticsubconscious.com/wiki/index.php

When logging into the wiki with a known good username and password when the user clicks the login button the page clears and the following error appears:

"Fatal error: Class 'SpecialResetpass' not found in /home/mbreen/autosub/www/wiki/includes/SpecialUserlogin.php on line 591

—71.192.156.183 03:35, 30 January 2010 (UTC)
 * This part of code only exists since 1.14.0, so check that you have to correct file in includes/SpecialUserlogin.php (if not, you can take it from our subversion repo). 08:14, 30 January 2010 (UTC)

I need to re-index so the search will work.
I try to run the proper scripts and this is what I get. I have version 1.6.10 running on OS X.

ns1:maintenance root# php rebuildtextindex.php <img src='/images/PetrineSabianismUNC.png' style='float:left;margin-right:1em' alt=''>Theosebia has a problem Sorry! This site is experiencing technical difficulties. Try waiting a few minutes and reloading. (Can't contact the database server: Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) (localhost)) ns1:maintenance root#

Thanks in advance! BJ

PHP has encountered an Access Violation at 01E6AC6A

 * MediaWiki version: 1.15.1
 * PHP version: php-5.2.12-Win32
 * MySQL version: 5.1
 * URL: http://localhost/index.php

I have just spend the last day installing PHP, MySQL and configuring IIS to allow me to run Mediawiki on a Windows 2003 server with IIS.

When I load the URL: http://localhost/index.php it take me to the

"MediaWiki 1.15.1 Please set up the wiki first. " page.

However when I try and configure Mediawiki for use and click "Install Mediawiki" I get the following error:

Please include all of the lines below when reporting installation problems.

PHP 5.2.12 installed Found database drivers for: MySQL PHP server API is isapi; using ugly URLs (index.php?title=Page_Title) Have XML / Latin1-UTF-8 conversion support. Warning: A value for session.save_path has not been set in PHP.ini. If the default value causes problems with saving session data, set it to a valid path which is read/write/execute for the user your web server is running under. PHP's memory_limit is 128M. Couldn't find Turck MMCache, eAccelerator, APC or XCache; cannot use these for object caching. GNU diff3 not found. Found GD graphics library built-in, image thumbnailing will be enabled if you enable uploads

PHP has encountered an Access Violation at 01E6AC6A

I have no idea what is causing this. I should add I am a SQL Server DBA who has been given the task of setting this up so php is not my area at all.

Please Help!

—Jkenne01 15:40, 22 February 2010 (UTC)

Parse Error on line 485 in RecentChange.php

 * MediaWiki version: 1.15.2
 * PHP version: 5.2.0-8+etch13
 * MySQL version: 5.0.32
 * URL: http://mitarbeiterforum.roteskreuz.at/wiki

Hi, The MediaWiki was installed properly without any error-message. It primarily looks good, but if you try to save any changes (anonymously or as registered user, you get a php-error-message: "Parse error: syntax error, unexpected $end in /home/oerk/htdocs/mitarbeiterforum.roteskreuz.at/wiki/includes/RecentChange.php on line 485"

I haven't found anything about this kind of error during my web-research.

—194.112.182.21 08:49, 26 March 2010 (UTC)