Project:Support desk/Sections/PHP

__NEWSECTIONLINK__

= PHP Error Support =

I can't upload files because PHP? errors?

 * MediaWiki version: 1.15.1
 * PHP version: 5.2.6 (cgi-fcgi)
 * MySQL version: 4.0.24-standard-log
 * URL: http://www.jasco-net.org/

Sorry, I can't write and read English...


 * First: After I collected file, Server displays two error messages bottom of upload page.
 * Warning: call_user_func(LocalFile::newFromTitle) [function.call-user-func]: First argument is expected to be a valid callback in /home/users/2/lolipop.jp-jasco/web/includes/filerepo/FileRepo.php on line 74
 * Warning: call_user_func(LocalFile::newFromTitle) [function.call-user-func]: First argument is expected to be a valid callback in /home/users/2/lolipop.jp-jasco/web/includes/filerepo/FileRepo.php on line 74
 * Next: After I click "Upload", Error messages of white display.
 * Warning: call_user_func(LocalFile::newFromTitle) [function.call-user-func]: First argument is expected to be a valid callback in /home/users/2/lolipop.jp-jasco/web/includes/filerepo/FileRepo.php on line 74
 * Fatal error: Call to a member function getName on a non-object in /home/users/2/lolipop.jp-jasco/web/includes/specials/SpecialUpload.php on line 444

Please tell me how to upload files... thank you.—Araisyohei 05:40, 27 November 2009 (UTC)

"Undefined variable: wgRequest" causes a fatal error

 * MediaWiki version: 1.15.1
 * PHP version: 5.3.1
 * MySQL version: 5.0.85
 * URL: http://wiki.liway.info/

I get the following error on wiki pages:

Notice: Undefined variable: wgRequest in /home/linfo/public_html/wiki/index.php on line 51

Fatal error: Call to a member function getVal on a non-object in /home/linfo/public_html/wiki/index.php on line 51

You can see it on the front page. I am not entirely sure when the error started happening, but it would be recently. *Maybe* it is related to the upgrade from php 5.3.0 to 5.3.1. Line 51 in index.php on my installation is the following:

$maxLag = $wgRequest->getVal( 'maxlag' );

Thank you

—Starcraftmazter 05:42, 3 December 2009 (UTC)

It occurs to me that this is a problem with PHP 5.3 or 5.3.1. When I went back to 5.2.11 the problem went away. Starcraftmazter 13:40, 9 December 2009 (UTC)

(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