Project:Support desk/Sections/PHP

__NEWSECTIONLINK__

= PHP Error Support =

Internal Error

 * MediaWiki version: upgraded to 1.15.1
 * PHP version: 5.2.3
 * MySQL version: 5.0.27

I get the following error when I click on certain links on my page in wiki.

''Internal error ''From Electronic Resources Wiki ''Jump to: navigation, search

''Expected attribute array, got something else in Xml::expandAttributes

''Backtrace:

''#0 D:\websites\Intranet_Lib\erwiki\includes\Linker.php(1042): Xml::expandAttributes(14) #1 D:\websites\Intranet_Lib\erwiki\includes\Parser.php(1403): Linker->makeExternalLink('http://libintra...', 'search the rela...', false, 'text', 14) #2 D:\websites\Intranet_Lib\erwiki\includes\Parser.php(1053): Parser->replaceExternalLinks('internalParse('parse('outputWikiText('view #7 D:\websites\Intranet_Lib\erwiki\includes\Wiki.php(450): CategoryPage->view #8 D:\websites\Intranet_Lib\erwiki\includes\Wiki.php(63): MediaWiki->performAction(Object(OutputPage), Object(CategoryPage), Object(Title), Object(User), Object(WebRequest)) #9 D:\websites\Intranet_Lib\erwiki\index.php(116): MediaWiki->initialize(Object(Title), Object(CategoryPage), Object(OutputPage), ''Object(User), Object(WebRequest)) #10 {main} ''

I did not have this problem when using MediaWiki 1.11

UPDATE: - I noticed a link between this error and my FCKEditor. If the editor is enabled then I get this error on some of the pages. If it's disabled then the pages work fine, but I can't use the editor. Any idea what I can do?

—Srutsam 18:43, 6 November 2009 (UTC)

Blank page after saving a new Page or edited

 * MediaWiki version: 1.15.1
 * PHP version: 5
 * Postgresql version: 8.4
 * URL: private
 * installed extensions: Discussion, QPoll, WikEd, Gadgets

Just installed wiki for the first time it seems to be running OK. Except when creating or editing a page click save button and wiki returns a blank page, so no redirect ????

Yet the new page is created or it has the modifications.

thanks —JustinG 14:14, 13 November 2009 (UTC)
 * See blank page. Max Semenik 15:24, 13 November 2009 (UTC)

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: www.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). " </b> ( 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

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

<?php if( defined( 'MEDIAWIKI' ) ) { require_once( 'SpecialPage.php' ); $wgExtensionFunctions[] = 'wfSpecialPageRating'; $wgExtensionCredits['specialpage'][] = array( 'name' => '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)