Fix MediaWiki internal error after installed the Extension:UserPageViewTracker

After installed the MediaWiki Extension:UserPageViewTracker, I met the "MediaWiki internal error". Fix the error by input the SQL query from the file "UserPageViewTracker/UserPageViewTracker.sql".



Error message:
MediaWiki internal error.
Original exception: [W6GxxYvEddf7YknS4P6BSwAAAAU] 2018-09-19 02:17:46: Fatal exception of type "Wikimedia\Rdbms\DBQueryError"
Exception caught inside exception handler.
Set $wgShowExceptionDetails = true; and $wgShowDBErrorBacktrace = true; at the bottom of LocalSettings.php to show detailed debugging information.
After enable the $wgShowExceptionDetails = true; and $wgShowDBErrorBacktrace = true; at the bottom of LocalSettings.php. The error message became:
MediaWiki internal error.
Original exception: [W6Gy6VItgYyPMbFFvLzEtgAAAAU] /index.php/Special:RecentChanges Wikimedia\Rdbms\DBQueryError from line 1457 of  /home/path/public_html/wiki/includes/libs/rdbms/database/Database.php: A database query error has occurred. Did you forget to run your application's database schema updater after upgrading?
Query: SELECT hits,last FROM `user_page_views` WHERE user_id = 2 AND page_id = 0 

Function: SpecialUserPageViewTracker::updateTable
Error: 1146 Table 'mediawiki_db_name.user_page_views' doesn't exist (localhost)  
Solution:

Because the table user_page_views was not exists in the MediaWiki database. I found the SQL script on this file "UserPageViewTracker/UserPageViewTracker.sql". To fix the database issue after the following SQL was input to phpMyAdmin or other MySQL clients.

CREATE TABLE IF NOT EXISTS /*_*/user_page_views (
 user_id INT(5) UNSIGNED NOT NULL,
 page_id INT(8) UNSIGNED NOT NULL,
 hits INT(10) UNSIGNED NOT NULL,
 last CHAR(14) DEFAULT NULL,
 PRIMARY KEY ( user_id, page_id )
);
CREATE OR REPLACE VIEW /*_*/user_page_hits AS SELECT
 u.user_name AS user_name,
 u.user_real_name AS user_real_name,
 p.page_namespace AS page_namespace,
 p.page_title AS page_title,
 v.hits AS hits,
 v.last AS last
FROM (/*_*/user u JOIN /*_*/page p) JOIN /*_*/user_page_views v
WHERE u.user_id = v.user_id AND p.page_id = v.page_id
ORDER BY u.user_id, v.hits DESC;

If you want to see the page view count from guest user on the special page ( Special:UserPageViewTracker ), you can adjust the second SQL syntax to:
CREATE OR REPLACE VIEW /*_*/user_page_hits AS SELECT
v.user_id,
COALESCE(u.user_name, "guest") AS user_name,
COALESCE(u.user_real_name, "guest") AS user_real_name,
p.page_namespace AS page_namespace,
p.page_title AS page_title,
v.hits AS hits,
v.last AS last
FROM /*_*/user_page_views v
LEFT JOIN /*_*/page p
ON v.page_id = p.page_id
LEFT JOIN /*_*/user u
ON u.user_id = v.user_id
WHERE p.page_title IS NOT NULL
ORDER BY v.user_id, v.hits DESC;
Versions:

MediaWiki 1.31.0

Logging:

After enable the $wgShowExceptionDetails = true; and $wgShowDBErrorBacktrace = true; at the bottom of LocalSettings.php. The error message became:
MediaWiki internal error.
Original exception: [W6Gy6VItgYyPMbFFvLzEtgAAAAU] /index.php/Special:RecentChanges Wikimedia\Rdbms\DBQueryError from line 1457 of  /home/path/public_html/wiki/includes/libs/rdbms/database/Database.php: A database query error has occurred. Did you forget to run your application's database schema updater after upgrading?
Query: SELECT hits,last FROM `user_page_views` WHERE user_id = 2 AND page_id = 0 

Function: SpecialUserPageViewTracker::updateTable
Error: 1146 Table 'mediawiki_db_name.user_page_views' doesn't exist (localhost)
Backtrace:
#0  /home/path/public_html/wiki/includes/libs/rdbms/database/Database.php(1427): Wikimedia\Rdbms\Database->makeQueryException(string, integer, string, string)
#1  /home/path/public_html/wiki/includes/libs/rdbms/database/Database.php(1200): Wikimedia\Rdbms\Database->reportQueryError(string, integer, string, string, boolean)
#2  /home/path/public_html/wiki/includes/libs/rdbms/database/Database.php(1653): Wikimedia\Rdbms\Database->query(string, string)
#3  /home/path/public_html/wiki/extensions/UserPageViewTracker/SpecialUserPageViewTracker.php(21): Wikimedia\Rdbms\Database->select(string, array, string, string)
#4  /home/path/public_html/wiki/includes/Hooks.php(177): SpecialUserPageViewTracker::updateTable(Parser, string)
#5  /home/path/public_html/wiki/includes/Hooks.php(205): Hooks::callHook(string, array, array, NULL)
#6  /home/path/public_html/wiki/includes/parser/Parser.php(1428): Hooks::run(string, array)
#7  /home/path/public_html/wiki/includes/parser/Parser.php(446): Parser->internalParseHalfParsed(string, boolean, boolean)
#8  /home/path/public_html/wiki/includes/OutputPage.php(1735): Parser->parse(string, Title, ParserOptions, boolean, boolean, NULL)
#9  /home/path/public_html/wiki/includes/OutputPage.php(1678): OutputPage->addWikiTextTitle(string, Title, boolean, boolean, boolean)
#10  /home/path/public_html/wiki/includes/OutputPage.php(3865): OutputPage->addWikiText(string)
#11  /home/path/public_html/wiki/includes/specialpage/SpecialPage.php(593): OutputPage->wrapWikiMsg(string, string)
#12  /home/path/public_html/wiki/includes/specialpage/ChangesListSpecialPage.php(667): SpecialPage->outputHeader()
#13  /home/path/public_html/wiki/includes/specials/SpecialRecentchanges.php(166): ChangesListSpecialPage->execute(NULL)
#14  /home/path/public_html/wiki/includes/specialpage/SpecialPage.php(522): SpecialRecentChanges->execute(NULL)
#15  /home/path/public_html/wiki/includes/specialpage/SpecialPageFactory.php(568): SpecialPage->run(NULL)
#16  /home/path/public_html/wiki/includes/MediaWiki.php(288): SpecialPageFactory::executePath(Title, RequestContext)
#17  /home/path/public_html/wiki/includes/MediaWiki.php(861): MediaWiki->performRequest()
#18  /home/path/public_html/wiki/includes/MediaWiki.php(524): MediaWiki->main()
#19  /home/path/public_html/wiki/index.php(42): MediaWiki->run()
#20 {main}
Exception caught inside exception handler: [W6Gy6VItgYyPMbFFvLzEtgAAAAU] /index.php/Special:RecentChanges Wikimedia\Rdbms\DBQueryError from line 1457 of  /home/path/public_html/wiki/includes/libs/rdbms/database/Database.php: A database query error has occurred. Did you forget to run your application's database schema updater after upgrading?
Query: SELECT hits,last FROM `user_page_views` WHERE user_id = 2 AND page_id = 0
Function: SpecialUserPageViewTracker::updateTable
Error: 1146 Table 'mediawiki_db_name.user_page_views' doesn't exist (localhost)
Backtrace:
#0  /home/path/public_html/wiki/includes/libs/rdbms/database/Database.php(1427): Wikimedia\Rdbms\Database->makeQueryException(string, integer, string, string)
#1  /home/path/public_html/wiki/includes/libs/rdbms/database/Database.php(1200): Wikimedia\Rdbms\Database->reportQueryError(string, integer, string, string, boolean)
#2  /home/path/public_html/wiki/includes/libs/rdbms/database/Database.php(1653): Wikimedia\Rdbms\Database->query(string, string)
#3  /home/path/public_html/wiki/extensions/UserPageViewTracker/SpecialUserPageViewTracker.php(21): Wikimedia\Rdbms\Database->select(string, array, string, string)
#4  /home/path/public_html/wiki/includes/Hooks.php(177): SpecialUserPageViewTracker::updateTable(Parser, string)
#5  /home/path/public_html/wiki/includes/Hooks.php(205): Hooks::callHook(string, array, array, NULL)
#6  /home/path/public_html/wiki/includes/parser/Parser.php(1428): Hooks::run(string, array)
#7  /home/path/public_html/wiki/includes/parser/Parser.php(446): Parser->internalParseHalfParsed(string, boolean, boolean)
#8  /home/path/public_html/wiki/includes/cache/MessageCache.php(1158): Parser->parse(string, Title, ParserOptions, boolean)
#9  /home/path/public_html/wiki/includes/Message.php(1244): MessageCache->parse(string, Title, boolean, boolean, LanguageZh_hans)
#10  /home/path/public_html/wiki/includes/Message.php(869): Message->parseText(string)
#11  /home/path/public_html/wiki/includes/Message.php(922): Message->toString(string)
#12  /home/path/public_html/wiki/includes/skins/Skin.php(682): Message->parse()
#13  /home/path/public_html/wiki/includes/skins/SkinTemplate.php(462): Skin->printSource()
#14  /home/path/public_html/wiki/includes/skins/SkinTemplate.php(249): SkinTemplate->prepareQuickTemplate()
#15  /home/path/public_html/wiki/includes/OutputPage.php(2388): SkinTemplate->outputPage()
#16  /home/path/public_html/wiki/includes/exception/MWExceptionRenderer.php(135): OutputPage->output()
#17  /home/path/public_html/wiki/includes/exception/MWExceptionRenderer.php(54): MWExceptionRenderer::reportHTML(Wikimedia\Rdbms\DBQueryError)
#18  /home/path/public_html/wiki/includes/exception/MWExceptionHandler.php(75): MWExceptionRenderer::output(Wikimedia\Rdbms\DBQueryError, integer)
#19  /home/path/public_html/wiki/includes/exception/MWExceptionHandler.php(149): MWExceptionHandler::report(Wikimedia\Rdbms\DBQueryError)
#20  /home/path/public_html/wiki/includes/MediaWiki.php(551): MWExceptionHandler::handleException(Wikimedia\Rdbms\DBQueryError)
#21  /home/path/public_html/wiki/index.php(42): MediaWiki->run()
#22 {main}


Photo material:

Free Photo of yellow, flower, sun - StockSnap.io (Thanks, Alecsandra!)

留言